dat <- data.frame(
age = rnorm(80, 5, 2),
weight = rnorm(80, 11, 2),
class = rbinom(80, 3, 0.5)
)
# Equal weights
score <- combine_variables(1 ~ age + weight + class, data = dat)
# Custom weights: age contributes 2x, weight 1.5x, class 1x
score <- combine_variables(1 ~ age + weight + class, data = dat,
weights = c(2, 1.5, 1))
Run the code above in your browser using DataLab