Reputation: 5210
just wondering why duplicated behaves the way it does with NAs:
> duplicated(c(NA,NA,NA,1,2,2))
[1] FALSE TRUE TRUE FALSE FALSE TRUE
where in fact
> NA == NA
[1] NA
is there a way to achieve that duplicated marks NAs as false, like this?
> duplicated(c(NA,NA,NA,1,2,2))
[1] FALSE FALSE FALSE FALSE FALSE TRUE
Upvotes: 13
Views: 3910
Reputation: 108533
You use the argument incomparables
for the function duplicated
like this :
> duplicated(c(NA,NA,NA,1,2,2))
[1] FALSE TRUE TRUE FALSE FALSE TRUE
> duplicated(c(NA,NA,NA,1,2,2),incomparables=NA)
[1] FALSE FALSE FALSE FALSE FALSE TRUE
It determines the values that cannot be compared (in this case NA
) and returns FALSE
for those values. See also ?duplicated
Upvotes: 25