[R] question about reshape

Henrique Dallazuanna wwwhsd at gmail.com
Thu Jan 28 19:23:46 CET 2010


Try this:

ong<-reshape(as.data.frame(dataset), idvar="subject",
v.names="response", varying=list(2:5), direction="long")
or
dataset <- cbind.data.frame(y1, y2, y3, y4)

On Thu, Jan 28, 2010 at 3:07 PM, Dana TUDORASCU <danatud at gmail.com> wrote:
>  Hello everyone,
>  I have a bit of a problem with reshape function in R.
>  I have simulated some normal data, which I have saved in 4 vectors.
>  y.1,y.2,y.3,y.4 which I combined a dataset:
> dataset<cbind(y1,y2,y3,y4). I have also generated some subject id number,
> and denoted that by subject.
>  So, my dataset looks like this:
>    subject       y.1        y.2       y.3       y.4
>  [1,]       1 20.302707 16.9643106 30.291031  7.118748
>  [2,]       2  9.942679  9.3674844  7.578465 16.494813
> ......etc, I have 20 subjects.
>  I want to transform this data into long form dataset, but it does not work.
>  I am using reshape command, and should be very straight forward...
>  Here is what I use:
>  long<-reshape(dataset, idvar="subject", v.names="response",
> varying=list(2:5), direction="long")
>
> Here is what I get:
> Error in d[, timevar] <- times[1L] : subscript out of bounds
>
> Now, do I get that error because the first column shows me the row number?
>  I have been using R for a while, but not a lot for data manipulations.
>  Any help would be great! Thank you in advance.
>  Dana
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list