data("credit_data", package = "modeldata")
## missing data per column
purrr::map_dbl(credit_data, function(x) mean(is.na(x)))
set.seed(342)
in_training <- sample(1:nrow(credit_data), 2000)
credit_tr <- credit_data[in_training, ]
credit_te <- credit_data[-in_training, ]
rec <- recipe(Price ~ ., data = credit_tr)
impute_rec <- rec %>%
step_indicate_na(Income, Assets, Debt)
imp_models <- prep(impute_rec, training = credit_tr)
imputed_te <- bake(imp_models, new_data = credit_te, everything())
Run the code above in your browser using DataLab