[R] aggregating using several functions

Christoph Scherber Christoph.Scherber at uni-jena.de
Mon Oct 24 16:55:39 CEST 2005


Dear R users,

I would like to aggregate a data frame using several functions at once 
(e.g., mean plus standard error).

How can I make this work using aggregate()?  The help file says scalar 
functions are needed; can anyone help?

Below is the code for my "meanse" function which I´d like to use like this:

aggregate(dataframe, list(factorA,factoB),meanse)

Thanks for your help!
Christoph





meanse<-function(x,...,na.rm=T){
if(na.rm)
x<-x[!is.na(x)]
m<-mean(x)
s<-sd(x)
l<-length(x)
serr<-s/sqrt(l)
return(data.frame(list("Mean"=m,"Std.Error"=serr)))
}




More information about the R-help mailing list