[R] aggregate() classing var. def.
Tord Snall
tord.snall at ebc.uu.se
Fri May 17 18:33:27 CEST 2002
Dear all,
I want to aggregate() my data based of the classes of a factors, just as in the
help file, but how do I define the "Region varable" in the ?aggregate example?
Now, the column is just like any other in my data matrix. As I understand it
from ?(state), state contains a matrix with the columns Pop, Income etc., but
Region is somehow separated. I noted below that as.list() is not enough.
Could someone please give me a hint.
Thanks in advance!
Sincerely,
Tord Snäll
data(state)
> aggregate(state.x77, list(Region = state.region), mean)
Region Population Income Illiteracy Life Exp Murder
Northeast 5495.111 4570.222 1.000000 71.26444 4.722222
South 4208.125 4011.938 1.737500 69.70625 10.581250
North Central 4803.000 4611.083 0.700000 71.76667 5.275000
West 2915.308 4702.615 1.023077 71.23462 7.215385
> aggregate(mydata, by=cell, sum)
Error in aggregate.data.frame(mydata, by = cell, sum) :
`by' must be a list
> aggregate(mydata, by=as.list(cell), sum)
Error in FUN(X[[1]], ...) : arguments must have same length
> aggregate(as.list(mydata), by=as.list(cell), sum)
Error in FUN(X[[1]], ...) : arguments must have same length
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list