[R] selecting values that are unique, instead of selecting unique values
Marc Schwartz
marc_schwartz at comcast.net
Wed Jun 25 18:37:12 CEST 2008
on 06/25/2008 11:29 AM Marc Schwartz wrote:
> on 06/25/2008 11:19 AM Daren Tan wrote:
>>
>> unique(c(1:10,1)) gives 1:10 (i.e. unique values), is there any
>> method to get only 2:10 (i.e. values that are unique) ?
>>
>
> The easiest might be:
>
> > Vec
> [1] 1 2 3 4 5 6 7 8 9 10 1
>
> > Vec[table(Vec) == 1]
> [1] 2 3 4 5 6 7 8 9 10
>
Correction!
That should be:
> which(table(Vec) == 1)
2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10
or if you don't want a named vector:
> as.vector(which(table(Vec) == 1))
[1] 2 3 4 5 6 7 8 9 10
My initial solution was incorrect and only worked because of the
ordering of the example vector.
Time for another cup of cawfee...Oy
Marc
More information about the R-help
mailing list