Add a 'final_score' column to a data frame that has been scored using
apply_scores()
by calculating a weighted mean of all other scores.
Arguments
- df
A data frame. The result of
apply_scores()
.- scores
scores A data frame of score specifications. See scores_init. This must be the same as the scores passed into
apply_scores()
.
See also
scores_init for the format of the
scores
table.apply_scores()
for the prior step.
Examples
data <- tibble::tibble(
x = 1:10
)
scores <- create_score(
scores_init,
score_type = "Linear", colname = "x", score_name = "Default",
weight = 1, lb = 1, ub = 6, exponential = FALSE
)
scores <- create_score(
scores,
score_type = "Peak", colname = "x", score_name = "Peak score",
weight = 2, lb = 2, ub = 8, centre = 5, inverse = FALSE,
exponential = FALSE
)
scored <- apply_scores(data, scores)
score_final(scored, scores)
#> # A tibble: 10 × 4
#> x `Score 1: x` `Peak score` final_score
#> <int> <dbl> <dbl> <dbl>
#> 1 1 0 0 0
#> 2 2 0.2 0 0.0667
#> 3 3 0.4 0.333 0.356
#> 4 4 0.6 0.667 0.644
#> 5 5 0.8 1 0.933
#> 6 6 1 0.667 0.778
#> 7 7 1 0.333 0.556
#> 8 8 1 0 0.333
#> 9 9 1 0 0.333
#> 10 10 1 0 0.333