# NOT RUN {
library(recipes)
n = 100
d <- tibble::tibble(encounter_id = 1:n,
patient_id = sample(1:20, size = n, replace = TRUE),
hemoglobin_count = rnorm(n, mean = 15, sd = 1),
hemoglobin_category = sample(c("Low", "Normal", "High", NA),
size = n, replace = TRUE),
disease = ifelse(hemoglobin_count < 15, "Yes", "No")
)
# Initialize
my_recipe <- recipe(disease ~ ., data = d)
# Create recipe
my_recipe <- my_recipe %>%
step_missing(all_nominal())
my_recipe
# Train recipe
trained_recipe <- prep(my_recipe, training = d)
# Apply recipe
data_modified <- bake(trained_recipe, new_data = d)
# }
Run the code above in your browser using DataCamp Workspace