[R] cross tabulate variables by subject id

2010-11-29 Thread Marianne Promberger
Dear list, I have data like this: dat1 - data.frame(subject=rep(1:10,2), cond1=rep(c(A,B),each=5), cond2=rep(c(C,D),each=10), choice=sample(0:1,10,replace=TRUE)) I would like to compare subjects' choice for (cond1==A cond2==C) vs

Re: [R] cross tabulate variables by subject id

2010-11-29 Thread Michael Bedward
Hi Marianne, How about this... ac.ad - unstack(dat1, choice ~ cond1:cond2)[, c(A.C, A.D)] acad.xtab - with(ac.ad, table(A.C, A.D)) Michael On 29 November 2010 20:18, Marianne Promberger marianne.promber...@kcl.ac.uk wrote: Dear list, I have data like this: dat1 -