[R] Group by in R

Duncan Murdoch murdoch at stats.uwo.ca
Mon Apr 13 13:02:43 CEST 2009


Nick Angelou wrote:
> Hi,
>
> I have the following table data:
>
> f1, f2, f3, f4.
>
> I want to compute the counts of unique combinations of f1-f4. In SQL I would
> just write:
>
> SELECT COUNT(*) FROM <table> GROUP BY f1, f2, ..,f4.
>
> How to do this in R?

table(f1,f2,f3,f4) will give you the counts.

Other statistics can by computed by group using the by() function.

Duncan Murdoch




More information about the R-help mailing list