[R] Reshaping a data frame
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) idvar1 var2 12345 gender_m 1 12345 age_22 1 12345 car_benz 1 12345 reader 28 23456 gender_f1 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 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Reshaping a data frame
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 28NA 5 23456NA NANA 30 1 10 34567 1 NANA NANA var2.age_35 var2.workwk var2.kid_0_3 var2.age_45 1 NA NA NA NA 51 401 NA 10 NA NA NA 1 -thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html