[R] count the # of appearances...
Marc Schwartz
marc_schwartz at comcast.net
Thu Mar 1 15:32:54 CET 2007
On Thu, 2007-03-01 at 15:20 +0100, bunny , lautloscrew.com wrote:
> Hi there,
>
> is there a possibility to count the number of appearances of an
> element in a vector ?
> i mean of any given element.. deliver all elements which are exactly
> xtimes in this vector ?
>
> thx in advance !!
Vec <- sample(20, replace = TRUE)
> Vec
[1] 16 4 16 1 13 13 7 14 20 18 18 18 6 1 8 5 12 8 5 2
# See ?table
> table(Vec)
Vec
1 2 4 5 6 7 8 12 13 14 16 18 20
2 1 1 2 1 1 2 1 2 1 2 3 1
# Get the elements that appear 3 times
Vec.tab <- table(Vec)
> Vec.tab[Vec.tab == 3]
18
3
HTH,
Marc Schwartz
More information about the R-help
mailing list