Skip to content

aggregating using several functions

1 message · Christoph Scherber

#
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)))
}