aggregate_and_document_scale: Aggregate variables and remember which variables this were

View source: R/data_wrangling.R

aggregate_and_document_scaleR Documentation

Aggregate variables and remember which variables this were

Description

Copied from codebook. The resulting variables will have the attribute scale_item_names containing the basis for aggregation. Its label attribute will refer to the common stem of the aggregated variable names (if any), the number of variables, and the aggregation function.

Usage

aggregate_and_document_scale(items, fun = rowMeans, stem = NULL)

Arguments

items

data.frame of the items that should be aggregated

fun

aggregation function, defaults to rowMeans with na.rm = FALSE

stem

common stem for the variables, specify if it should not be auto-detected as the longest common stem of the variable names

Examples

testdf <- data.frame(bfi_neuro_1 = rnorm(20), bfi_neuro_2 = rnorm(20),
                    bfi_neuro_3R = rnorm(20), age = rpois(20, 30))
item_names <- c('bfi_neuro_1', 'bfi_neuro_2', 'bfi_neuro_3R')
testdf$bfi_neuro <- aggregate_and_document_scale(testdf[, item_names])
testdf$bfi_neuro

rubenarslan/formr documentation built on Feb. 6, 2024, 1:18 a.m.