Skip to content
Prev 68254 / 398503 Next

Aggregating data (with more than one function)

I am looking for an answer to a similar question - a generalized
solution that would be able to apply
   (1) any number of functions
   (2) to any number of vectors
   (3) by any number of factors 
(just like SQL's group by). 
The output data frame must contain the values of the by factors, to be
used for joins.

Aggregate() does (2) and (3). The solutions posted to this thread
(split+sapply, by, tapply) do (1) and (3) (or so it seems to me). What
would be the best way to get to (1)+(2)+(3)?

I am inclined to use aggregate() in a loop with 
eval(parse(text="aggregate expression here")). 
Running
groupby <- do.call("rbind", by(var_i, list(a,b,c,d,e,f),
	function(x) c(fct1(x),fct2(x),fct3(x),fct4(x))))
in a loop (var_1, var_2 etc) would be very nice but I don't know how
to add a-f as columns in the output data frame.

Thank you,
b.
On Mon, 2005-03-28 at 19:15 -0600, Sivakumaran Raman wrote:
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html