um exemplo reproduzivel... set.seed(1) da = data.frame(Trat=sample(6, 1000, rep=T), x=rnorm(1000), y=rexp(1000, 1)) aggregate(da[,-1], by=list(Trat=da[['Trat']]), function(x) c(media=mean(x, na.rm=T), stderr=sd(x, na.rm=T))) b