Skip to contents

This function computes mean scores for specified scales derived from a given data frame. The scales are anticipated to be represented as columns in the data frame that begin with a base name specified in the scale list. Items that require reverse scoring (identified by "reverse" or "Reverse" in the item name) are automatically reversed before calculating the mean. An option is provided to rename reversed scored items. If a clustering variable is specified, the function also computes cluster-level means for each newly computed variable.

Usage

get_means(
  data,
  scale_list,
  reverse_score = TRUE,
  rename_reversed_items = FALSE,
  order = 1,
  cluster = NULL
)

Arguments

data

A data frame containing the scales and items.

scale_list

A vector of characters representing the base names of the scales to compute.

reverse_score

A logical indicating whether reverse scoring should be applied. Default is TRUE.

rename_reversed_items

A logical indicating whether to rename reverse scored items by replacing "reverse" with "reversed". Default is FALSE.

order

An integer indicating the order of the scale. Use 1 for first order scales and 2 for second order scales. Default is 1.

cluster

A character string representing the column name used for clustering. If provided, the function computes cluster-level means for each new variable. Default is NULL.

Value

A data frame with new columns of computed mean scale scores. If a cluster variable was provided, additional columns representing cluster-level mean variables are added.