[R] Group by in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Apr 13 14:08:00 CEST 2009


Mike Lawrence wrote:
> One way:
> 
> g= paste(f1,f2,f3,f4)
> table(g)

I'd go for

g <- interaction(f1,f2,f3,f4, drop=TRUE)
table(g)

which is essentially the same thing.

> 
> On Mon, Apr 13, 2009 at 7:33 AM, Nick Angelou <nikolay12 at yahoo.com> 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?
>>
>> Thanks,
>>
>> Nick
>> --
>> View this message in context: http://www.nabble.com/Group-by-in-R-tp23020587p23020587.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at 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.
>>
> 
> 
> 


-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list