Possible Duplicate:
Aggregate R sum
I have a data frame that looks like this:
sample value
1 a 1
2 a 2
3 b 3
4 b 4
5 b 5
6 c 6
I need to collapse the data frame over the levels of sample
(may be a character vector or a factor), adding all the value
s, so my resulting data frame looks like this:
sample sum
1 a 3
2 b 12
3 c 6
It's Monday morning, and all I can think of is writing a complicated for
loop. How might I vectorize this using apply, plyr, etc?