I have this vector
vector <- c("www.one","www.two","www.one","www.three")
and I want to find all duplicates, including the first occurrence of the duplicated value. If I do
dup <- duplicated(vector)
I get
dup
# [1] FALSE FALSE TRUE FALSE
while I need to get
# [1] TRUE FALSE TRUE FALSE
You can call duplicated
twice, looking for duplicates from the front and from the back.
duplicated(vector) | duplicated(vector, fromLast=TRUE)
# [1] TRUE FALSE TRUE FALSE
Here's another way:
Rgames> foo<-c('a','b','d','f','a','b','b','q')
Rgames> which(foo%in%foo[which(duplicated(foo))])
[1] 1 2 5 6 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With