replace_missing: Replace missing values in a vector

Description Usage Arguments Value Examples

View source: R/Missing_Values.R

Description

Replace missing values in a vector with either the mode, median, or mean of the vector, removing NA values in the calculation.

Usage

1
replace_missing(vec, method = "mode", with, return_imputed = FALSE)

Arguments

vec

Vector in which to replace missing values.

method

The method to use to determine the imputed value.

with

The value to impute missing values with (if specified, method will be ignored).

return_imputed

Whether or not to return the value that missing elements were imputed with.

Value

Vector with missing values replaced as desired, or a list of that and the replacement (imputed) value.

Examples

1
2
3
4
5
6
7
replace_missing(c(1, 1, 1, 2, NA))
replace_missing(c(1, 1, 1, 2, NA), method = "mode") # Same as above
replace_missing(c(1, NA, 1, 2), method = "median")
replace_missing(c(1, NA, 1, 2), method = "mean")
replace_missing(c(1, NA, 1, 2), method = "mean", return_imputed = TRUE)
replace_missing(c(1, NA, 1, 2), with = 5)
replace_missing(c(1, NA, 1, 2), method = "mean", with = 5)

KO112/KO documentation built on Oct. 2, 2020, 9:21 a.m.