powered by
Calculate an index based on multiple conditions. Each condition is evaluated and the result is weighted and summed to produce the final index.
calculate_index(.df, ..., .weight = 1, .na_replace = 0)
A numeric vector of index scores
A data frame
Conditions to evaluate. See examples for more details.
Weight for each condition, should be of length 1 or equal to the number of conditions.
Value to replace NA, should be of length 1 or equal to the number of conditions.
NA
df <- data.frame(x = c(1, 2, 3, 4, 5), y = c(1, 2, NA, 4, NA)) calculate_index(df, x > 3, y < 3, .weight = c(1, 2), .na_replace = 0)
Run the code above in your browser using DataLab