subtotalArray {crunch}R Documentation

Calculate the transforms from a CrunchCube

Description

applyTransforms calculates transforms (e.g. Subtotals) on a CrunchCube. Currently only the row transforms are supported. This is useful if you want to use the values from the subtotals of the CrunchCube in an analysis.

Usage

subtotalArray(x, ...)

## S4 method for signature 'CrunchCube'
subtotalArray(x, headings = FALSE)

applyTransforms(
  x,
  array = cubeToArray(x),
  transforms_list = transforms(x),
  dims_list = dimensions(x),
  useNA = x@useNA,
  ...
)

Arguments

x

a CrunchCube

...

arguments to pass to calcTransforms, for example include

headings

for subtotalArray: a logical indicating if the headings should be included with the subtotals (default: FALSE)

array

an array to use, if not using the default array from the cube itself. (Default: not used, pulls an array from the cube directly)

transforms_list

list of transforms to be applied (default: transforms(x))

dims_list

list of dimensions that correspond to array (default: dimensions(x))

useNA

useNA parameter from the CrunchCube to use (default: x@useNA)

Details

Including the include argument allows you to specify which parts of the CrunchCube to return. The options can be any of the following: "cube_cells" for the untransformed values from the cube itself, "subtotals" for the subtotal insertions, and "headings" for any additional headings. Any combination of these can be given, by default all will be given.

subtotalArray(cube) is a convenience function that is equivalent to applyTransforms(cube, include = c("subtotals"))

Value

an array with any transformations applied

Examples

## Not run: 
# to get an array of just the subtotals
subtotalArray(crtabs(~opinion, ds))
#    Agree Disagree
#       47       35

# to get the full array with the subtotals but not headings
applyTransforms(crtabs(~opinion, ds), include = c("cube_cells", "subtotals"))
#             Strongly Agree             Somewhat Agree                      Agree
#                         23                         24                         47
# Neither Agree nor Disagree          Strongly Disagree                   Disagree
#                         18                         19                         35
#          Somewhat Disagree
#                         16
# to get the full array with the headings but not subtotals
applyTransforms(crtabs(~opinion, ds), include = c("cube_cells", "headings"))
#               All opinions             Strongly Agree             Somewhat Agree
#                         NA                         23                         24
# Neither Agree nor Disagree          Strongly Disagree          Somewhat Disagree
#                         18                         19                         16

## End(Not run)


[Package crunch version 1.30.4 Index]