I was wondering whats wrong with my code and found that the reason for my odd results was this unexpected handling of NA's by ==
and %in%
.
> NA %in% NA
[1] TRUE
> NA == NA
[1] NA
Is there a reason for this? I've been reading about the ==
operator and its handling of NA
's but couldn't find any information on why the %in%
operator handles NA's differently.
If you look at the NA
documentation using ?"=="
, it states that "Missing values (NA) and NaN values are regarded as non-comparable even to themselves, so comparisons involving them will always result in NA. "
Note also that you can use the identical function i.e. identical(NA,NA)
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