1

In SQL I can get a count using group by like this:

select
  column1,
  column2,
  column3,
  count(*)
from
  table
group by
  column1,
  column2,
  column3;

How is this done in R? I have a dataframe with the ungrouped data.


UPDATE

I eventually got this to work via:

grouped_data <- aggregate(data, by=list(data$column1, data$column2, data$column3), FUN=length);
Edward J. Stembler
  • 1,932
  • 4
  • 30
  • 53
  • This is also very straight forward in R and has been answered many times in FAQs, on SO and around the interwebs... What have you tried so far that hasn't worked? – Justin Sep 26 '13 at 20:48

1 Answers1

2

I eventually got this to work via:

grouped_data <- aggregate(data, by=list(data$column1, data$column2, data$column3), FUN=length);
Edward J. Stembler
  • 1,932
  • 4
  • 30
  • 53
  • 2
    You can also explore the formula mode. Without seeing any sample data, try something like: `aggregate(. ~ column1 + column2 + column3, data, length)`. Also, it is OK to *accept* your own answer since that makes it clear to others viewing the question that there is an accepted answer available. – A5C1D2H2I1M1N2O1R2T1 Sep 27 '13 at 01:56