R Equality in ignoring NA

Is there an equivalent == , but with the result that x != NA if x not NA ?

The following does what I want, but it is awkward:

 mapply(identical, vec1, vec2) 
+7
source share
1 answer

1 == NA returns a logical NA , not TRUE or FALSE . If you want to call NA FALSE , you can add a second condition:

 set.seed(1) x <- 1:10 x[4] <- NA y <- sample(1:10, 10) x <= y # [1] TRUE TRUE TRUE NA FALSE TRUE TRUE FALSE TRUE FALSE x <= y & !is.na(x) # [1] TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE FALSE 

You can also use the second processing step to convert all NA values ​​from the equality test to FALSE .

 foo <- x <= y foo[is.na(foo)] <- FALSE foo # [1] TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE FALSE 

In addition, for what does NA == NA cost NA == NA , like NA != NA .

+5
source

All Articles