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

2007-06-07 Thread Guanrao Chen
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

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

2007-06-07 Thread jim holtman
This seems to work fine: x - ca, la, 12 + ca, sd, 22 + ca, la, 33 + nm, al, 9 + ma, lx, 18 + ma, bs, 90 + ma, lx, 22 + table - read.csv(textConnection(x), header=FALSE) aggregate(table$V3,list(table$V1,table$V2),mean) Group.1 Group.2x 1 nm al 9.0 2 ma bs 90.0 3