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

Thomas Neitmann

base

61 Words

2020-02-03 01:00 +0700

53b1dba @ 2020-03-22

comments powered by Disqus