dimSums: Collapse an array from a CrunchCube by summing across...

View source: R/cube-collapse-dimensions.R

dimSumsR Documentation

Collapse an array from a CrunchCube by summing across dimensions to remove

Description

Typically when collapsing a crosstab you can just sum across the dimensions that you want to collapse across. However, because we have array-type questions/dimensions we have to be a little bit smarter. We cannot sum across any subvariable dimension (dimension types ending with "_items") because that would inflate the number of respondents by approximately the number of subvariables. Instead, we take the mean across any "_items" dimension. In principle, we could just take a single item or unique across the "_items" dimensions, however due to floating point differences + rounding there are minute differences that pop up, mean smooths over those tiny differences.

Usage

dimSums(x, margin = NULL)

Arguments

x

the CrunchCube to collapse

margin

the margins that should be summed within (in other words: the dimension that will be retained)

Details

dimSums returns a cube that retains the dimensions given in margin and collapses all the others. This is useful if you want to get counts that are equivalent to a univariate cube from a multivariate cube. For example dimSums(crtabs(~ fruit + pets, ds), 1) will be equal to crtabs(~ fruit, ds) and dimSums(crtabs(~ fruit + pets, ds), 2) will be equal to crtabs(~ pets, ds).

Value

a duly-collapsed CrunchCube


crunch documentation built on Aug. 31, 2023, 1:07 a.m.