Try this:

aggregate(val ~ grp, dta, length)


On Fri, Oct 8, 2010 at 11:28 AM, Marcus Drescher <dresc...@tum.de> wrote:

> 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
>
> ______________________________________________
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to