Great! What about character variables? Which methods can be used to remove NA
s from them? When working with character values, we usually replace NA
s with:
- The most frequent category of the variable.
- 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 NA
s 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 NA
s with some other string, such as "unknown":
"male", "unknown", "female", "female", "unknown"