[R] counting numbers without replicates in a vector

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Thu Dec 16 22:50:24 CET 2004



Jun Ding wrote:

> 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?
> 

How about using ?table:

tab <- table(a)
unq <- names(tab)[tab == 1]

Then use as.numeric(unq) to convert the names to numbers if needed.

--sundar




More information about the R-help mailing list