SummaryStat: Summary insertions

View source: R/summary-insertions.R

SummaryStat-classR Documentation

Summary insertions

Description

Just like subtotals()s, summary statistics can be inserted into cubes. SummaryStat() makes an object of type SummaryStat which can be added on to a CrunchCube's insertions to add the specified summary statistic. Currently only mean and median are supported; both use weighted algorithms to go from counts and numeric values of categories to the expected statistic. Although SummaryStat objects can be made by hand, it is recommended instead to use the addSummaryStat() function which is much quicker and easier to simply add a summary statistic to an existing CrunchCube.

Usage

SummaryStat(
  name,
  stat,
  categories = NULL,
  position = c("relative", "top", "bottom"),
  after = NULL,
  before = NULL,
  includeNA = FALSE
)

SummaryStat(
  name,
  stat,
  categories = NULL,
  position = c("relative", "top", "bottom"),
  after = NULL,
  before = NULL,
  includeNA = FALSE
)

is.SummaryStat(x)

are.SummaryStats(x)

Arguments

name

character the name of the summary statistic

stat

a function to calculate the summary (e.g. mean or median)

categories

character or numeric the category names or ids to be included in the summary statistic, if empty all categories

position

character one of "relative", "top", or "bottom". Determines the position of the subtotal or heading, either at the top, bottom, or relative to another category in the cube (default)

after

character or numeric if position is "relative", then the category name or id to position the subtotal or heading after

before

character or numeric if position is relative (and the insertion type allows it - currently only MR subtotals).

includeNA

should missing categories be included in the summary?

x

for is.SummaryStat() only, an object to test if it is a SummaryStat object

Details

Summary statistics are intended only for CrunchCube objects, and are not able to be set on Crunch variables.

Removing transforms

noTransforms() is useful if you don't want to see or use any transformations like Subtotals and Headings. This action only applies to the CrunchCube object in R: it doesn't actually change the variables on Crunch servers or the query that generated the CrunchCube.


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