# NOT RUN {
library(recipes)
library(modeldata)
data(biomass)
biomass$total <- apply(biomass[, 3:7], 1, sum)
biomass_tr <- biomass[biomass$dataset == "Training",]
biomass_te <- biomass[biomass$dataset == "Testing",]
rec <- recipe(HHV ~ carbon + hydrogen + oxygen + nitrogen +
sulfur + total,
data = biomass_tr)
ratio_recipe <- rec %>%
# all predictors over total
step_ratio(all_numeric_predictors(), denom = denom_vars(total)) %>%
# get rid of the original predictors
step_rm(all_predictors(), -ends_with("total"))
ratio_recipe <- prep(ratio_recipe, training = biomass_tr)
ratio_data <- bake(ratio_recipe, biomass_te)
ratio_data
# }
Run the code above in your browser using DataLab