Replaces NA values in all numeric columns using specified filling method.

fill_na(df, mode = "value", value = 0)

Arguments

df

Input data frame

mode

Filling method: "value" - fill with constant value (default) "mean" - fill with column mean "median" - fill with column median "locf" - last observation carried forward "nocb" - next observation carried backward

value

Value to use when mode = "value" (default 0)

Value

Data frame with NA values filled

Examples

df <- data.frame(a = c(1, NA, 3), b = c(NA, 2, NA))
fill_na(df) # fills with 0
#>   a b
#> 1 1 0
#> 2 0 2
#> 3 3 0
fill_na(df, mode = "mean")
#>   a b
#> 1 1 2
#> 2 2 2
#> 3 3 2
fill_na(df, mode = "locf")
#>   a  b
#> 1 1 NA
#> 2 1  2
#> 3 3  2