Exercise

Using replace_with_na scoped variants

To reduce code repetition when replacing values with NA, use the "scoped variants" of replace_with_na():

  • replace_with_na_at()
  • replace_with_na_if()
  • replace_with_na_all()

The syntax of replacement looks like this:

~.x == "N/A"

This replaces all cases that are equal to "N/A".

~.x %in% c("N/A", "missing", "na", " ")

Replaces all cases that have "N/A", "missing", "na", or " ".

Instructions

100 XP

For the dataset pacman replace the same special missing values, "N/A", "missing", "na", and " ":

  • year, month, and day, using replace_with_na_at().
  • Only character variables using replace_with_na_if().
  • All variables using replace_with_na_all().