Hi:

How about

> as.data.frame(with(df, table(group, level, color)))
  group level color Freq
1     A     1  blue    1
2     B     1  blue    1
3     A     2  blue    1
4     B     2  blue    2
5     A     1   Red    1
6     B     1   Red    0
7     A     2   Red    2
8     B     2   Red    2

where df is the name of the data frame.

HTH,
Dennis

On Tue, May 11, 2010 at 5:38 PM, Noah Silverman <n...@smartmediacorp.com>wrote:

> Hi,
>
> 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
> etc..
>
>
> 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 factors.
>
> Any suggestions?
>
> Thanks
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to