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.

subtotalArray(x, ...)

# S4 method for CrunchCube

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 for subtotalArray: a logical indicating if the headings should be included with the subtotals (default: FALSE) an array to use, if not using the default array from the cube itself. (Default: not used, pulls an array from the cube directly) list of transforms to be applied (default: transforms(x)) list of dimensions that correspond to array (default: dimensions(x)) useNA parameter from the CrunchCube to use (default: x@useNA)

## Value

an array with any transformations applied

## 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"))

## Examples

if (FALSE) {
# 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
}