[R] counting numbers without replicates in a vector

Berton Gunter gunter.berton at gene.com
Thu Dec 16 22:57:20 CET 2004

?duplicated and ?unique might be of interest to you ...

But I think an easier way is:


This gives you the count. 
names(z)[z==1]   gives you the actual values

(The quotes can be removed by explicitly calling print with argument

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Jun Ding
> Sent: Thursday, December 16, 2004 1:41 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] counting numbers without replicates in a vector
> Hi,
> I am just wondering if there is an easy way to count
> in a numeric vector how many numbers don't have
> replicates. 
> For example, 
> a=c(1,1,2,2,3,4,5), how can I know there are three
> numbers (3, 4 and 5) without replicates?
> Thank you!
> Jun
> =====
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html

More information about the R-help mailing list