[R] Faster alternative to by?

michael watson (IAH-C) michael.watson at bbsrc.ac.uk
Wed Jul 26 14:41:31 CEST 2006


Hi

I have a data.frame, two columns, 12304 rows.  Both columns are factors.
I want to do an equivalent of an SQL "group by" statement, and count the
number of rows in the data frame for each unique value of the second
column.

I have:

countl <- by(mapped, mapped$col2, nrow)

Now, mapped$col2 has 10588 levels, so this statement takes a really long
time to run.  Is there a more efficient way of doing this in R?

Thanks

Mick



More information about the R-help mailing list