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


Great! What about character variables? Which methods can be used to remove NAs from them? When working with character values, we usually replace NAs with:

  1. The most frequent category of the variable.
  2. Some value that is not used in this variable.

Suppose you have the following character vector:

a <- c("male", NA, "female", "female", NA)

Here, the categories are "male" and "female". Using method #1 discussed above, you would replace NAs with "female" because it is the most frequently occurring category. In that case, the vector a will be defined like this:

"male", "female",   "female",  "female", "female"

Alternatively, we could use the second approach and replace the NAs with some other string, such as "unknown":

"male", "unknown",   "female", "female", "unknown"


The most frequently occurring value in the air_conditioner column is "Y". Replace all NA values in this column with "Y".

Stuck? Here's a hint!

Use the function when filtering rows.