Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close


Interesting, right? The resulting data frame displays NAs for missing records! This is because R does not know how to compare NA with 500.

Obviously, missing values are problematic in analysis, so it's usually best to somehow remove them. Only then can we work on further analyzing the data. But if we can't use operators when one of the operands is NA, how are we going to detect or display missing values? Well, as usual, there's a function for that!

The is.na() function takes a single vector argument and returns a logical vector populated with TRUE and FALSE values. An element in the logical vector returned by is.na() will only be TRUE if the corresponding element in the original vector is NA. It will be FALSE otherwise. Here's an example of a vector with some missing values:

a <- c(2, 3, 4, 5, NA, NA)

The expression is.na(a) will return the following:



As you've already seen, the yard_area column of the houses data frame contains some missing values. Display a logical vector that tells us which elements of yard_area are missing.

Stuck? Here's a hint!

Simply use the is.na() function on the houses$yard_area column.