[R] How to count the number of occurence?

David Winsemius dwinsemius at comcast.net
Sat Mar 20 16:21:30 CET 2010


On Mar 20, 2010, at 3:43 AM, tj wrote:

>
> Hi, may I ask for your help...
> What is the R code if I want to count the number of times that "2"  
> appeared
> in the following R output
>
>> k
> [1] 1 1 1 1 1 1 3 1 2 1 1 1 1 1 1 1 1 3 2 1 1 4 1 1 1 1 1 5 1 1

sum(k==2)

>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list