Learn R Programming

FBMS (version 1.3)

impute_x: Impute Missing Values in the Data

Description

Imputes missing values in the data using median imputation based on the data set.

Usage

impute_x(object, x)

Value

A matrix with imputed values and additional columns for missingness indicators.

Arguments

object

A fitted model object with an "imputed" attribute indicating columns to impute.

x

A matrix or data frame

Examples

Run this code
# \donttest{
set.seed(123)
x <- matrix(rnorm(60), 10, 6)
colnames(x) <- paste0("X", 1:6)
x[1:2, 1] <- NA  # Introduce missing values
model <- list(imputed = c(1))
attr(model, "imputed") <- c(1)
x_imputed <- impute_x(model, x)
dim(x_imputed)  # 10 rows, 7 columns (6 original + 1 missingness indicator)
any(is.na(x_imputed))  # FALSE, no missing values
# }

Run the code above in your browser using DataLab