Fills NA by a stated rule so an estimator that cannot proceed on
incomplete rows has an explicit alternative to dropping them
(G2.14c). The rule is always the caller's choice – nothing is
imputed implicitly anywhere in the package.
Usage
morie_impute_column(x, method = c("median", "mean", "mode", "locf"))Details
"median" and "mean" suit a roughly symmetric or skewed numeric
column respectively. "mode" is the only sensible option for a
categorical column. "locf" (last observation carried forward)
assumes the rows are in a meaningful order – time, usually – and is
wrong if they are not.
Imputing narrows the apparent spread of a variable: the imputed
values carry no information but are counted as if they did, so any
downstream standard error is optimistic. n_imputed is returned so
that cost stays visible.
Examples
morie_impute_column(c(1, 2, NA, 4), "median")$values
#> [1] 1 2 2 4
