[R] Reshaping a data frame
Thomas Lumley
tlumley at u.washington.edu
Sat Feb 26 18:20:49 CET 2005
On Sat, 26 Feb 2005, Matthew Pharr wrote:
> but I am uncertain of how to instruct R to reshape the data
> set because I
> need to move var1 (var1 is a survey question) out wide while placing
> the values of var2 (var2 is the answer to the survey question) under
> the correct survey question. Thank you for any help provided.
You want var1 to be the "timevar":
> reshape(a,direction="wide",timevar="var1",idvar="id")
id var2.gender_m var2.age_22 var2.car_benz var2.reader var2.gender_f
1 12345 1 1 1 28 NA
5 23456 NA NA NA 30 1
10 34567 1 NA NA NA NA
var2.age_35 var2.workwk var2.kid_0_3 var2.age_45
1 NA NA NA NA
5 1 40 1 NA
10 NA NA NA 1
-thomas
More information about the R-help
mailing list