The documentation of aggregate tells you that your way will not work. Why don't you aggregate/sum the columns separately? I would doubt that what you want to try to achieve in one go is already implemented somewhere....
Jannis --- Hongwei Dong <pdxd...@gmail.com> schrieb am Di, 22.2.2011: > Von: Hongwei Dong <pdxd...@gmail.com> > Betreff: [R] "aggregate" in R > An: r-help@r-project.org > Datum: Dienstag, 22. Februar, 2011 22:25 Uhr > Hi, R users, > > I'm wondering how I can aggregate data in R with different > functions for > different columns. For example: > > x<-rep(1:5,3) > y<-cbind(x,a=1:15,b=21:35) > y<-data.frame(y) > > I want to aggregate "a" and "b" in y by "x". With "a", I > want to use > function "mean"; with "b", I want to use function "sum". I > tried: > > > aggregate(y,x,mean(y$a),sum(y$b)) > > But I got the error: > > Error in match.fun(FUN) : > 'mean(y$a)' is not a function, character or symbol > > > Anyone can tell me how to fix this problem? Thanks. > > Gary > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org > mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.