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
In addition, for what does NA == NA cost NA == NA , like NA != NA .
Justin
source share