Re: [R] aggregate vs tapply; is there a middle ground?

2006-02-12 Thread Hans Gardfjell
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 -

[R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread Joseph LeBouton
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

[R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread Hans Gardfjell
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

Re: [R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread hadley wickham
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

Re: [R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread Joseph LeBouton
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

Re: [R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread Peter Dalgaard
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 -