This is a wrapper of base::replace()
with a simplified interface and a name
that target the specific job of filling NA's. See also tidyr::replace_na
and dplyr::coalesce
.
fill_na(x, filler = 0)
x | A dataframe. |
---|---|
filler | A filler; whatever you want to replace NA's with. |
A modified version of x
.
Other general functions to edit data in place: lookup
x <- data.frame(x = c(NA, 1), y = c("a", NA), stringsAsFactors = FALSE) a_dataframe <- x fill_na(a_dataframe)#> x y #> 1 0 a #> 2 1 0fill_na(a_dataframe, "")#> x y #> 1 a #> 2 1fill_na(a_dataframe, "missing")#> x y #> 1 missing a #> 2 1 missing#> x y #> [1,] "0" "a" #> [2,] " 1" "0"a_vector <- x$x fill_na(a_vector)#> [1] 0 1#> [[1]] #> x y #> 1 0 a #> 2 1 0 #> #> [[2]] #> x y #> 1 0 a #> 2 1 0 #> #> [[3]] #> x y #> 1 0 a #> 2 1 0 #>