The right way to check for NAs
To check for missing values in R
you might be tempted to use the equality operator ==
with your vector on one side and NA
on the other. Don’t!
If you insist, you’ll get a useless results.
x <- c(1, NA, 3)
x == NA
## [1] NA NA NA
Instead use the is.na()
function.
is.na(x)
## [1] FALSE TRUE FALSE