tabloop_f: Tabulation loop

View source: R/tabloop.R

tabloop_fR Documentation

Tabulation loop

Description

tabloop_f tabulates a data frame (e.g. summarize ndistinct) over fixed and looped by variables, binding all output as a single data frame.

Usage

tabloop_f(
  df,
  count,
  dcount,
  sum,
  mean,
  median,
  loop,
  fixed = NULL,
  filter = FALSE,
  rename = FALSE,
  suppress = FALSE,
  rounding = 1,
  ...
)

Arguments

df

A data frame in tidy format

count

A variable that identifies the unit of tabulation for non-distinct counts

dcount

A variable that identifies the unit of tabulation for distinct counts

sum

A variable that identifies the unit of tabulation for sums

mean

A variable that identifies the unit of tabulation for calculating means

median

A variable that identifies the unit of tabulation for calculating medians

loop

A list of the loop by variables, requires use of list_var, required

fixed

A list of the fixed by variables, requires use of list_var, defaults to null

filter

Specifies whether results should be filtered to positive values only for binary variables, defaults to false

rename

Specifies whether results group categories should be renamed according to APDE defauts, defaults to false

suppress

Specifies whether suppression should be applied

rounding

Specifies how many decimal places to round mean and median to

Details

This function tabulates a single data frame over fixed and looped by variables, and binds all output as a single data frame. Fixed by variables are variables by which the data frame will be disaggregated for all loop variables, whereas loop variables will only be disaggregated separately. For example, a combination of region for fixed and age group and sex for loop would produce counts by age group and sex for each region, but not counts for each sex by age group.

The function accepts a row ID variable and summarizes distinct counts of this variable. The function will produce zero counts for all by variable values that exist in the full join of the fixed and loop by variable matrix.

Examples

## Not run: 
tabloop_f(df = mcaid_cohort, unit = id, loop = list_var(gender, race), fixed = list_var(region))
tabloop_f(df = mcaid_cohort, unit = id, loop = list_var(gender, race, zip_code, cov_grp, language))
tabloop_f_test(df = depression, dcount = list_var(id), count = list_var(hra_id),
               sum = list_var(ed_cnt, inpatient_cnt, depression_ccw), mean = list_var(age), median = list_var(age),
               loop = list_var(gender_mx), filter = T, rename = T, suppress = T, 
               suppress_var = list_var(id_dcount), round = 3)

## End(Not run)


PHSKC-APDE/Medicaid documentation built on April 24, 2024, 6:09 p.m.