[R] Reshaping a data frame

Matthew Pharr matthewpharr at gmail.com
Sat Feb 26 17:46:39 CET 2005


I am new to R. Having come from SPSS and SAS to this program, I know
that my problem is
reshaping from long to wide. How would I go about reshaping data frame
(A) so that
information for each record is contained on one row. I am aware of the
R reshape
function, 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.

*Data Frame (A)

id        var1               var2

12345  gender_m      1
12345  age_22          1
12345  car_benz       1
12345  reader           28
23456  gender_f        1
23456  age_35          1
23456  workwk         40
23456  reader           30
23456  kid_0_3         1
34567  gender_m      1
34567  age_45          1

*Data Frame (B)
  id     gender_m  age_22  car_benz  reader 
12345       1             1           1           28




More information about the R-help mailing list