I have a data frame and some columns have NA
values.
How do I replace these NA
values with zeroes?
The cleaner
package has an na_replace()
generic, that at default replaces numeric values with zeroes, logicals with FALSE
, dates with today, etc.:
starwars %>% na_replace()
na_replace(starwars)
It even supports vectorised replacements:
mtcars[1:6, c("mpg", "hp")] <- NA
na_replace(mtcars, mpg, hp, replacement = c(999, 123))
Documentation: https://msberends.github.io/cleaner/reference/na_replace.html