[R] How to get duplicated items in a vector?

Peng Yu pengyu.ut at gmail.com
Fri Oct 2 04:42:11 CEST 2009


Hi,

> x=c(rep(1,3),rep(3,2))
> x
[1] 1 1 1 3 3
> duplicated(x)
[1] FALSE  TRUE  TRUE FALSE  TRUE
>

As shown in the above code, 'duplicated' doesn't return 'F' for the
first '1' and first '3' in 'x'. I am wondering if there is a function
that can return an indicator for any element whether it appears in a
vector twice or more.

Regards,
Peng




More information about the R-help mailing list