[R] counting numbers without replicates in a vector

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Dec 16 23:42:50 CET 2004


Ray Brownrigg <ray at mcs.vuw.ac.nz> writes:

> > 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:
> length(table(a)[table(a) == 1])

Also, probably inefficient, but rather neat:

> setdiff(a,a[duplicated(a)])
[1] 3 4 5


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list