Description Usage Arguments Details Value See Also Examples
impute
returns a vector with missing values imputed.
1 |
x |
A vector. |
method |
Either a value, a vector of values, or a function to use for imputation. See Details for more information. |
... |
Additional arguments for |
impute
returns the vector x
with missing values imputed via method
.
impute
is designed to be readable from the function call.
For example:
impute(x, -1)
can be read as
"impute missing values for x as -1".
impute(x, mean)
can be read as
"impute missing values for x as the mean".
impute(x, sample, replace=TRUE)
can be read as
"impute missing values for x using random sampling with replacement".
method
can either be a value, a vector of values, or a function. Standard recycling
is used if the vector of values is less than the number of NA
values. When method
is a function it takes only the non-NA
values as input so that there is no need to
supply those pesky na.rm=TRUE
arguments. :)
The output of impute
is the vector x
with missing values imputed.
Other imputers: impute_ecdf
,
impute_mode
, impute_sample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | x <- c(1, 1, 2, 3, NA, NA)
#####
# Common use cases
#
# I want to impute the mean!
x_mean <- impute(x, mean)
data.frame(x, x_mean)
# I want to impute missing values as -1 (e.g. for inclusion in a regression analysis)
x_m1 <- impute(x, -1)
data.frame(x, x_m1)
# I want to impute as "Missing"! (e.g. for inclusion in a regression analysis)
x_missing <- impute(x, "Missing")
data.frame(x, x_missing)
#####
# Using the impute helper functions
#
# I want to impute the most common category!
x_mode <- impute(x, impute_mode)
data.frame(x, x_mode)
# I want to impute from the empirical cdf!
x_ecdf_1 <- impute(x, impute_ecdf)
x_ecdf_2 <- impute(x, impute_ecdf)
data.frame(x, x_ecdf_1, x_ecdf_2)
# I want to impute using sampling with replacement!
x_sample_1 <- impute(x, impute_sample)
x_sample_2 <- impute(x, impute_sample)
data.frame(x, x_sample_1, x_sample_2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.