Description Usage Arguments Value Examples
View source: R/Missing_Values.R
Replace missing values in a vector with either the mode, median, or mean of the vector, removing NA values in the calculation.
1 | replace_missing(vec, method = "mode", with, return_imputed = FALSE)
|
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. |
Vector with missing values replaced as desired, or a list of that and the replacement (imputed) value.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.