[R] Count values in a dataframe with respect to groups

Marcus Drescher drescher at tum.de
Fri Oct 8 16:28:40 CEST 2010


Dear all,

I am looking for a function to count values belonging to a class within a dataframe (and ignore NAs).

grp = c(1,1,1, 1,2, 2,2)
val = c(2,1,5,NA,3,NA,1)

dta = data.frame(grp=grp, val=val)

The result should look like:

grp count
 1    3
 2    2

At the moment, I am trying to find a function for FUN in aggregate, but with no success. Can anybody help me?

Thanks in advance.
Marcus



More information about the R-help mailing list