Replace missing values

na_replace(df, how = NULL, value = NULL)

Arguments

df

The data set(data.frame or vector) for which replacements are required

how

How should missing values be replaced? One of ffill, samples,value or any other known method e.g mean, median, max ,min. The default is NULL meaning no imputation is done. For character vectors, the use of `get_mode` is also supported. No implementation for class factor(yet).

value

If how is set to value, this allows the user to provide a specific fill value for the NAs.

Value

A data.frame object with missing values replaced.

Details

This function currently does not support grouping although this may be achieved with some inaccuracies using grouping functions from other packages.

Examples

head(na_replace(airquality,how="value", value="Missing"))
#>     Ozone Solar.R Wind Temp Month Day
#> 1      41     190  7.4   67     5   1
#> 2      36     118  8.0   72     5   2
#> 3      12     149 12.6   74     5   3
#> 4      18     313 11.5   62     5   4
#> 5 Missing Missing 14.3   56     5   5
#> 6      28 Missing 14.9   66     5   6