library(recipes)
data(biomass, package = "modeldata")
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),
keep_original_cols = FALSE)
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