[R] trouble with summary tables with several variables using aggregate function

2011-05-19 Thread Luma R
Dear all, I am having trouble creating summary tables using aggregate function. given the following table: Var1 Var2Var3 dummy S1 T1 I 1 S1 T1 I 1 S1 T1 D1 S1 T1 D1 S1 T2 I 1

Re: [R] trouble with summary tables with several variables using aggregate function

2011-05-19 Thread Phil Spector
Luma - If I understand you correctly, I think the easiest way to get what you want is to use the reshape function on the output from aggregate: reshape(Count.Cells,idvar=c('Var1','Var2'),timevar='Var3',direction='wide') Var1 Var2 dummy.D dummy.I 1 S1 T1 2 2 2 S2 T1

Re: [R] trouble with summary tables with several variables using aggregate function

2011-05-19 Thread Marc Schwartz
Another approach, using aggregate(), presuming that the data is in a data frame called 'DF': with(DF, aggregate(Var3, list(Var1 = Var1, Var2 = Var2), table)) Var1 Var2 x.D x.I 1 S1 T1 2 2 2 S2 T1 2 2 3 S1 T2 2 2 4 S2 T2 0 4 HTH, Marc Schwartz On May 19,

Re: [R] trouble with summary tables with several variables using aggregate function

2011-05-19 Thread Dennis Murphy
Hi: The dummy column really isn't necessary. Here's another way to get the result you want. Let d be the name of your example data frame. d - d[, 1:3] (dtable - as.data.frame(ftable(d, row.vars = c(1, 2 Var1 Var2 Var3 Freq 1 S1 T1D2 2 S2 T1D2 3 S1 T2D2 4

Re: [R] trouble with summary tables with several variables using aggregate function

2011-05-19 Thread Dennis Murphy
Oops, didn't see Marc's reply. His solution is much more compact. For R 2.11.0 and above, aggregate() now has a formula interface that usually works nicely: aggregate(Var3 ~ Var1 + Var2, data = d, FUN = table) Var1 Var2 Var3.D Var3.I 1 S1 T1 2 2 2 S2 T1 2 2 3 S1

Re: [R] trouble with summary tables with several variables using aggregate function

2011-05-19 Thread Luma R
Thank you all for the help and solutions presented! Luisa On Thu, May 19, 2011 at 9:33 PM, Dennis Murphy djmu...@gmail.com wrote: Oops, didn't see Marc's reply. His solution is much more compact. For R 2.11.0 and above, aggregate() now has a formula interface that usually works nicely: