[R] Wide to long form conversion

Jim Lemon jim at bitwrit.com.au
Fri Oct 7 13:16:40 CEST 2011


On 10/07/2011 07:28 AM, Gang Chen wrote:
> I have some data 'myData' in wide form (attached at the end), and
> would like to convert it to long form. I wish to have five variables
> in the result:
>
> 1) Subj: factor
> 2) Group: between-subjects factor (2 levels: s / w)
> 3) Reference: within-subject factor (2 levels: Me / She)
> 4) F: within-subject factor (2 levels: F1 / F2)
> 5) J: within-subject factor (2 levels: J1 / J2)

Hi Gang,
I don't know whether this is the format you want, but:

library(prettyR)
rep_n_stack(mydata,matrix(c(2,3,6,7,4,5,8,9),nrow=2,byrow=TRUE))

Jim



More information about the R-help mailing list