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 ______________________________________________ [email protected] 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.
