Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dimSums

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

Crunch.io Data Tools

v1.28.0
LGPL (>= 3)
Authors
Greg Freedman Ellis [aut, cre], Jonathan Keane [aut], Mike Malecki [aut], Neal Richardson [aut], Gordon Shotwell [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.