Thanks Peter!
I had a feeling that there must be a simpler, better, more elegant
solution.
/Hans
Peter Dalgaard wrote:
hadley wickham [EMAIL PROTECTED] writes:
I faced a similar problem. Here's what I did
tmp -
Dear all,
I'm wanting to do a series of comparisons among 4 categorical variables:
a - aggregate(y, list(var1, var2, var3, var4), sum)
This gets me a very nice 2-dimensional data frame with one column per
variable, BUT, as help for aggregate says, empty subsets are
removed. I don't see in
I faced a similar problem. Here's what I did
tmp -
data.frame(A=sample(LETTERS[1:5],10,replace=T),B=sample(letters[1:5],10,replace=T),C=rnorm(10))
tmp1 - with(tmp,aggregate(C,list(A=A,B=B),sum))
tmp2 - expand.grid(A=sort(unique(tmp$A)),B=sort(unique(tmp$B)))
merge(tmp2,tmp1,all.x=T)
At least
I faced a similar problem. Here's what I did
tmp -
data.frame(A=sample(LETTERS[1:5],10,replace=T),B=sample(letters[1:5],10,replace=T),C=rnorm(10))
tmp1 - with(tmp,aggregate(C,list(A=A,B=B),sum))
tmp2 - expand.grid(A=sort(unique(tmp$A)),B=sort(unique(tmp$B)))
merge(tmp2,tmp1,all.x=T)
At
Thanks, Phil! I've literally spent two hours on my own trying to find
something that does exactly that. Thanks for another pair of functions
added to my (slowly!) growing R vocabulary.
-jlb
Phil Spector wrote:
Joseph -
I'm sure there are clearer and more efficient ways to do it, but
hadley wickham [EMAIL PROTECTED] writes:
I faced a similar problem. Here's what I did
tmp -
data.frame(A=sample(LETTERS[1:5],10,replace=T),B=sample(letters[1:5],10,replace=T),C=rnorm(10))
tmp1 - with(tmp,aggregate(C,list(A=A,B=B),sum))
tmp2 -