Data Science Desktop Survival Guide
by Graham Williams |
|||||
Replacing Missing Values |
20201026 See Section 9.11 to impute (guess) values to replace missing values.
To replace missing values (NA) in a data set with a specific default value, like 0 for numeric data, we can use tidyr::replace_na() within a pipeline. In the following example only the numeric columns of the dataset are considered dplyr::across() the dataset, by checking tidyselect::where() the data base::is.numeric().
ds %>%
mutate(across(where(is.numeric), ~replace_na(.x, 0)))
|