| mean_imp_col | R Documentation |
Impute missing values in a matrix by replacing them with the mean of their respective columns.
mean_imp_col(obj, subset = NULL, cores = 1)
obj |
A numeric matrix. |
subset |
Optional character or integer vector specifying columns to
impute. If |
cores |
Integer. Number of cores to use for parallel computation.
Defaults to |
Columns with no observed values cannot be imputed by their column mean and are left unchanged.
A numeric matrix of the same dimensions as obj, with missing
values in the selected columns replaced by column means.
obj <- matrix(c(1, 2, NA, 4, NA, 6, NA, 8, 9, NA, NA, NA), nrow = 3)
colnames(obj) <- c("A", "B", "C", "D")
obj
# impute missing values with column means
mean_imp_col(obj)
# impute only specific columns by name
mean_imp_col(obj, subset = c("A", "C"))
# impute only specific columns by index
mean_imp_col(obj, subset = c(1, 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.