Thank you all for the help and solutions presented!
Luisa
On Thu, May 19, 2011 at 9:33 PM, Dennis Murphy 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:
>
> aggregate(Var3 ~
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 T
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
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, 20
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
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
S1
6 matches
Mail list logo