tidy_avg_rows: Updated version of 'average_rows()'

Description Usage Arguments Value See Also

Description

Average values across multiple columns for each row of a data.frame

Usage

1
2
tidy_avg_rows(data, selector, reverse = NULL, show = F, mini = NULL,
  maxi = NULL)

Arguments

data

a data.frame to use for averaging across rows

selector

a dplyr::select helper function, for example starts_with()

reverse

a numeric vector indicating items or variables to reverse code using reverse.code from the psych package.

show

choose whether or not show the results of the reverse coding. If TRUE, the result of the function will be a data.frame with the original columns passed to the function along with the reverse coded columns denoted with an "_r". Useful for checking to make sure reverse coding was done to the appropriate columns.

mini

the minimum value of a scale score (used when reverse = T)

maxi

the maximum value of a scale score (used when reverse = T)

Value

a vector of the averaged values for each row from the specified columns of the data frame.

This function, and those specified below in 'See Also', work best when used inside a call to dplyr's mutate() for creating new variables. The point of the function is to make it easy to use select helpers from the tidyselect (and used in dplyr extensively) to select variables for aggregation, such as an average score for a number of questionnaire items, the sum of correct responses, or finding the number of missing values in a row.

See Also

tidy_sum_rows for row summing, tidy_sum_missings for summing missing values, and tidy_sd_rows for calculating standard deviations across rows.


ethan-young/esyr documentation built on May 15, 2019, 12:45 p.m.