library(naniar)
x <- c(1:5, NA, NA, NA)
x
replace_na_with(x, 0L)
replace_na_with(x, "unknown")
library(dplyr)
dat <- tibble(
ones = c(NA,1,1),
twos = c(NA,NA, 2),
threes = c(NA, NA, NA)
)
dat
dat %>%
mutate(
ones = replace_na_with(ones, 0),
twos = replace_na_with(twos, -99),
threes = replace_na_with(threes, "unknowns")
)
dat %>%
mutate(
across(
everything(),
\(x) replace_na_with(x, -99)
)
)
Run the code above in your browser using DataLab