Calculates the sum across multiple variables for each row. This is the
R equivalent of SPSS's COMPUTE total = SUM(var1, var2, var3).
Use min_valid to require a minimum number of non-missing items,
mirroring SPSS's SUM.n() syntax.
Arguments
- data
Your survey data (a data frame or tibble). When used inside
mutate(), pass.or usepick().- ...
The variables to average. Use bare column names separated by commas, or tidyselect helpers like
starts_with("trust"). If no variables are specified, all numeric columns indataare used (useful withpick()).- min_valid
Minimum number of non-missing values required to compute a mean. If a row has fewer valid values,
NAis returned. Default isNULL(compute mean if at least 1 value is valid).- na.rm
Remove missing values before calculating? Default:
TRUE.
Details
When to Use row_sums() vs row_means()
row_means(): For Likert-type scales where you want an average score (preserves the original scale range)row_sums(): For count-based scores (e.g., number of symptoms endorsed) or when you need a total score
See also
row_means() for row-wise means, row_count() for counting
specific values
Other scale:
efa(),
pomps(),
reliability(),
row_count(),
row_means()
Examples
library(dplyr)
data(survey_data)
# Total score across items
survey_data <- survey_data %>%
mutate(total = row_sums(., trust_government, trust_media, trust_science))
# With min_valid (like SPSS SUM.3)
survey_data <- survey_data %>%
mutate(total = row_sums(., trust_government, trust_media,
trust_science, min_valid = 3))
