Get startedGet started for free

Using replace_with_na

Following on from the previous dataset, we now know that we have a few strange missing values.

Now, we are going to do something about it, and replace these values with missings (e.g. NA) using the function replace_with_na().

This exercise is part of the course

Dealing With Missing Data in R

View Course

Exercise instructions

For the pacman dataset:

  • Using replace_with_na(), replace missing values "N/A", "na", and "missing" with NA for the year, and score variables.
  • Test to see if you have removed all the missing values using miss_scan_count() at the end.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Print the top of the pacman data using `head()`
head(___)

# Replace the strange missing values "N/A", "na", and  
# "missing" with `NA` for the variables, year, and score
pacman_clean <- replace_with_na(_____, replace = list(year = c(___, ___, ___),
                                score = c(___, ___, ___)))
                                        
# Test if `pacman_clean` still has these values in it?
miss_scan_count(____, search = list(___, ___, ___))
Edit and Run Code