[R] Omiting repeated values
Oleg Sklyar
osklyar at ebi.ac.uk
Wed Feb 21 14:24:52 CET 2007
Hi,
'unique' or its combination with 'match' if you need to keep the vector
the same length will do it:
> a<-c(1,2,4,2,5,5,6,7,8)
> unique(a)
[1] 1 2 4 5 6 7 8
> a[ which( is.na( match(1:length(a), match(unique(a),a)) ) ) ]=NA
> a
[1] 1 2 4 NA 5 NA 6 7 8
This is probably not the best implementation, but it does the job.
'table' will also give you the number of occurances of unique values:
> a<-c(1,2,4,2,5,5,6,7,8)
> table(a)
a
1 2 4 5 6 7 8
1 2 1 2 1 1 1
Oleg
stat stat wrote:
> Dear all R users,
>
> Is there any function to omit repeated values in a vector? Your help will be highly appreciated.
>
> Thanks
> stat
>
>
> ---------------------------------
> Here’s a new way to find what you're looking for - Yahoo! Answers
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
--
Dr Oleg Sklyar * EBI/EMBL, Cambridge CB10 1SD, England * +44-1223-494466
More information about the R-help
mailing list