[R] Reshape function

Jun Yan jyan at stat.wisc.edu
Sat Nov 2 07:24:04 CET 2002


Suppose the wide dataframe is dat.w, and variable ID is a unique 
id for each row. Something like the following may work:

dat.l <- reshape(dat.w, idvar="ID", varying=list(c("Day1", "Day2",
"Day3")), v.names="Response", timevar="Day", direction="long")

Notice here, I assumed Day1, Day2, and Day3 are variable Response at
different days. So I named the new variable "Response", and the new time
variable "Day".

Jun

On Fri, 1 Nov 2002, DAVID JENSEN wrote:

> Can someone help me with the proper usage of the
> reshape function?
> 
> Let's say I have a dataset with columns like this
> (wide format):
> 
> Id  Sex  Group   Test   Day1   Day 2  Day 3...
>      
> And I want to transpose this into something like this
> (thin):
> 
> Id    Sex   Group    Test   Time
> 
> Where the new column labeled time contains all the
> time variables (Day 1, Day 2, Day 3...) that were in
> the wide format.  I just cannot get it to work right
> using the reshape function.  I'm sure there is
> something that I'm missing.  I just can't get a handle
> on how to use this reshape function.
> 
> Thanks so much in advance for any help.
> 
> Dave

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list