total_scores.Rd
Calculate the total scores from sets of scores
total_scores(.data, ..., .method = "mean", .append = FALSE, .drop = FALSE)
A data frame with columns to summed or averaged over.
A comma separated set of named tidy selectors, each of which selects a set of columns to which to apply the totalling function.
The method used to calculate the total. Must be one of "mean", "sum", or "sum_like". The "mean" is the arithmetic mean, skipping missing values. The "sum" is the sum, skipping missing values. The "sum_like" is the arithmetic mean, again skipping missing values, multiplied by the number of elements, including missing values.
logical If FALSE, just the totals be returned. If TRUE, the totals are appended as new columns to original data frame.
logical If .append is TRUE, and if .drop is TRUE, then the variables being aggregated over are not returned.
A new data frame with columns representing the total scores.
# Calculate the mean of all items beginning with `x_` and separately all items beginning with `y_`
total_scores(test_psychometrics, x = starts_with('x_'), y = starts_with('y_'))
#> # A tibble: 44 × 2
#> x y
#> <dbl> <dbl>
#> 1 2 2
#> 2 1.8 1.8
#> 3 2.1 2.8
#> 4 1.78 2.3
#> 5 1.1 1.6
#> 6 1.6 2.11
#> 7 2.5 3.2
#> 8 1.8 2.3
#> 9 1.5 2.2
#> 10 1.5 1.8
#> # ℹ 34 more rows
# Calculate the sum of all items beginning with `z_` and separately all items beginning with `x_`
total_scores(test_psychometrics, .method = 'sum', z = starts_with('z_'), x = starts_with('x_'))
#> # A tibble: 44 × 2
#> z x
#> <dbl> <dbl>
#> 1 22 20
#> 2 17 18
#> 3 17 21
#> 4 30 16
#> 5 33 11
#> 6 27 16
#> 7 19 25
#> 8 17 18
#> 9 30 15
#> 10 23 15
#> # ℹ 34 more rows
# Calculate the mean of all items from `x_1` to `y_10`
total_scores(test_psychometrics, xy = x_1:y_10)
#> # A tibble: 44 × 1
#> xy
#> <dbl>
#> 1 2
#> 2 1.8
#> 3 2.45
#> 4 2.05
#> 5 1.35
#> 6 1.84
#> 7 2.85
#> 8 2.05
#> 9 1.85
#> 10 1.65
#> # ℹ 34 more rows
# Calculate the mean of all items beginning with `x_` and separately all items beginning with `y_`,
# but append these means to the original, after have dropping the variables that
# are aggregated over
total_scores(test_psychometrics, x = starts_with('x_'), y = starts_with('y_'), .append = T, .drop = T)
#> # A tibble: 44 × 12
#> z_1 z_2 z_3 z_4 z_5 z_6 z_7 z_8 z_9 z_10 x y
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2 2 3 3 1 2 3 3 1 2 2 2
#> 2 1 1 1 2 1 2 2 2 4 1 1.8 1.8
#> 3 1 NA 2 2 3 2 2 1 2 2 2.1 2.8
#> 4 2 3 3 5 4 4 2 2 2 3 1.78 2.3
#> 5 4 4 4 3 3 3 3 5 3 1 1.1 1.6
#> 6 3 2 2 3 3 2 4 4 3 1 1.6 2.11
#> 7 2 2 1 1 2 2 1 3 2 3 2.5 3.2
#> 8 3 1 1 1 1 2 1 1 2 4 1.8 2.3
#> 9 2 3 3 3 3 3 4 2 4 3 1.5 2.2
#> 10 3 3 1 2 3 1 2 2 3 3 1.5 1.8
#> # ℹ 34 more rows