Impute.numeric {COINr} | R Documentation |
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.
## S3 method for class 'numeric'
Impute(x, f_i = NULL, f_i_para = NULL, ...)
x |
A numeric vector, possibly with |
f_i |
A function that imputes missing values in a numeric vector. See description and details. |
f_i_para |
Optional further arguments to be passed to |
... |
arguments passed to or from other methods. |
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
.
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.
An imputed numeric vector of the same length of x
.
# a vector with a missing value
x <- 1:10
x[3] <- NA
x
# impute using median
# this calls COINr's i_median() function
Impute(x, f_i = "i_median")