Imputes missing values in a numeric vector using a function f_i
. This function should return a vector identical
to x
except for NA
values, which can be replaced. The function f_i
is not required to replace all NA
values.
Usage
# S3 method for class 'numeric'
Impute(x, f_i = NULL, f_i_para = NULL, ...)
Details
This calls the function f_i()
, with optionally further arguments f_i_para
, to impute any missing
values found in x
. By default, f_i = "i_mean()"
, which simply imputes NA
s with the mean of the
non-NA
values in x
.
COINr has several built-in imputation functions of the form i_*()
for vectors which can be called by Impute()
. See the
online documentation for more details.
You could also use one of the imputation functions directly (such as i_mean()
). However, this
function offers a few extra advantages, such as checking the input and output formats, and making
sure the resulting imputed vector agrees with the input. It will also skip imputation entirely if
there are no NA
s at all.
Examples
# a vector with a missing value
x <- 1:10
x[3] <- NA
x
#> [1] 1 2 NA 4 5 6 7 8 9 10
# impute using median
# this calls COINr's i_median() function
Impute(x, f_i = "i_median")
#> [1] 1 2 6 4 5 6 7 8 9 10