[ top | up ]
Extract Unique Elements
Syntax
unique(x)
Description
unique returns a vector like x
but with duplicate elements removed.
If an element is equal to one with a smaller
index, it is removed.
See Also
duplicated which gives the indices of duplicated elements
Examples
unique(c(3:5, 11:8, 8 + 0:5))
length(unique(sample(100,100,replace=T))) #- what do you expect ?
my.unique <- function(x) x[!duplicated(x)]
for(i in 1:4) {x <- rpois(100, pi); print(all(unique(x) == my.unique(x))) }