data(credit_data, package = "modeldata")
is.na(credit_data) %>% colSums()
# If the test passes, `new_data` is returned unaltered
recipe(credit_data) %>%
check_missing(Age, Expenses) %>%
prep() %>%
bake(credit_data)
# If your training set doesn't pass, prep() will stop with an error
if (FALSE) {
recipe(credit_data) %>%
check_missing(Income) %>%
prep()
}
# If `new_data` contain missing values, the check will stop `bake()`
train_data <- credit_data %>% dplyr::filter(Income > 150)
test_data <- credit_data %>% dplyr::filter(Income <= 150 | is.na(Income))
rp <- recipe(train_data) %>%
check_missing(Income) %>%
prep()
bake(rp, train_data)
if (FALSE) {
bake(rp, test_data)
}
Run the code above in your browser using DataLab