[R] Selecting distinct values from a column

Marc Schwartz MSchwartz at MedAnalytics.com
Fri Nov 19 21:47:51 CET 2004


On Fri, 2004-11-19 at 19:01 +0000, Ann Huxtable wrote:
> Hello,
> 
> Is there an easy way (other than the obvious for loop?) to select distinct 
> values from a column vector?
> 
> Many thanks
> 
> Ann


Presuming that by 'distinct' you mean 'unique', see ?unique

> MyVec <- rep(1:5, times = c(1:5))

> MyVec
 [1] 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5

> unique(MyVec)
[1] 1 2 3 4 5


HTH,

Marc Schwartz




More information about the R-help mailing list