tally_scale | R Documentation |
This function aggregates responses from a set of columns into a single score which gets appended as a new column, e.g. sum or mean score
tally_scale( df, var_regex, new_var_name = NULL, join_function = dplyr::full_join, na.rm = F, tally_function = sum )
df |
Dataframe of data |
var_regex |
Regex string to capture column names which will be aggregated |
new_var_name |
Optional argument defining the column name for the aggregate score. If no value is supplied, the new column will be named the value of var_regex |
join_function |
Optional argument specifying join function. If NULL, aggregated values will be returned without original data |
na.rm |
Optional argument passed to tally_function |
tally_function |
Function used to tally scores, e.g. mean, sum, etc. |
A dataframe with tallyed scales appended or dataframe with tallyed scales alone
library(dplyr) df <- tribble( ~scale_sub1_1, ~scale_subscale1_2, ~scale_subscale2_1, ~scale_subscale2_2, 1, 2, 3, 3, 2, 3, 2, 3, 3, 2, 3, 3 ) df %>% tally_scale("^scale_(subscale1|subscale2)_[0-9]$", "scale_total") %>% tally_scale("^scale_subscale1_[0-9]$", "scale_subscale1_total") %>% tally_scale("^scale_subscale2_[0-9]$", "scale_subscale2_total")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.