[R] Summarizing counts by multiple factors

Noah Silverman noah at smartmediacorp.com
Wed May 12 02:38:07 CEST 2010


An example data set is:

group    level    color
A        1        "blue"
A        1        "Red"
B        1        "blue"
B        2        "Red"
A        2        "Red"
B        2        "Red"
B        2        "blue"
B        2        "blue"
A        2        "blue"
A        2        "Red"

I'd like to compute a summary of counts for each combination of group, 
level, color.

An example output would be something like this:
group    level    color        count
A        1        "blue"        1
A        2        "red"        2
B        2        "red"        2

The tapply function seems to do this for a single variable, but I can 
figure out to to do it for combinations of more than one factor.  I also 
see the ave function, but can't figure out how to apply it to multiple 

Any suggestions?


More information about the R-help mailing list