Replace missing values
na.replace(x, replace, ...)Vector with missing values (NA) replaced by the value of
replace.
This is a convenience function that is the same as x[is.na(x)] <- replace
x <- c(1, 2, 3, NA, 6, 7, 8, NA, NA)
# Replace with a specified value
na.replace(x, "999")
#> [1] "1" "2" "3" "999" "6" "7" "8" "999" "999"
# Replace with the calculated median
na.replace(x, median, na.rm = TRUE)
#> [1] 1.0 2.0 3.0 4.5 6.0 7.0 8.0 4.5 4.5