[R] "aggregate" in R
Jannis
bt_jannis at yahoo.de
Wed Feb 23 00:16:42 CET 2011
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 <pdxdong at gmail.com> schrieb am Di, 22.2.2011:
> Von: Hongwei Dong <pdxdong at gmail.com>
> Betreff: [R] "aggregate" in R
> An: r-help at 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 at 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.
>
More information about the R-help
mailing list