This function adds composites (item means by default). The Cronbach's alpha is also printed to the console.
Usage
add_composites(
df,
map,
fn = rowMeans,
na.rm = TRUE,
standardize_items = FALSE,
check_already_exist = FALSE,
...
)Arguments
- df
data.frame
- map
named list where names are new variable names, elements are character vectors with variable names to use
- fn
function to apply to each row (default
base::rowMeans())- na.rm
(logical) remove missing (NA) before computing composite? (default
TRUE)- standardize_items
(logical) standardize items before computing composite? (default
FALSE)- check_already_exist
(logical) stop if variable already exists? (default
FALSE)- ...
other arguments passed to
fn()
Details
Function in fn must take na.rm as an argument, and return a vector with
a value for each row in df. Good candidate functions are base::rowMeans()
and base::rowSums(). Users can also supply custom functions.