[R] aggregate by two columns, "sum" not working while "mean" is

Guanrao Chen guanrao at yahoo.com
Thu Jun 7 18:46:05 CEST 2007


Dear Fellow Rers,

I have a table looks like this:

ca, la, 12
ca, sd, 22
ca, la, 33
nm, al, 9
ma, lx, 18
ma, bs, 90
ma, lx, 22

I want to sum the 3rd column grouped by the first and
the second column, so the result look like this table:

ca, la, 45 <
ca, sd, 22
nm, al, 9
ma, lx, 40 <
ma, bs, 90

The two rows with < are sums.

I tried
aggregate(table,list(table$V1,table$V2),sum/mean), sum
was not working while mean worked.

Can anybody give a hint?

Thanks.
Guanrao



More information about the R-help mailing list