freqTable: Generate a frequency table

Description Usage Arguments Value Examples

View source: R/QCMemo_script.R

Description

The function freqTable is somewhat analagous to PROC FREQ in SAS. The functionality is slightly different and more limited, but the results are aesthetically similar.

Usage

1
2
3
4
5
6
7
8
9
freqTable(
  inputds,
  variables,
  varnames = variables,
  n = TRUE,
  percent = TRUE,
  perc_digits = 1,
  bg = "aliceblue"
)

Arguments

inputds

A dataset with one row per unit (i.e. a Step 2 dataset).

variables

A vector of names indicating the variables you would like to be cross-tabulated.

varnames

A named list giving key-value pairs for how you would like the variables to be labeled on the table.

n

Logical. Should frequencies be displayed?

percent

Logical. Should percents be displayed?

perc_digits

A number indicating how many decimal places should be displayed for the percentages.

bg

The background color for the columns containing the calculated statistics. Can be given as either a name (e.g. "dodgerblue4") or using the rgb function.

Value

A flextable object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Simple cross-tabulation using default options
freqTable(inputds    = mtcars,
          variables  = c('cyl', 'gear', 'carb'))

# Using options to customize table further
freqTable(inputds    = mtcars,
          variables  = c('cyl', 'gear', 'carb'),
          varnames   = list(cyl = 'Cylinders', gear = 'Forward gears', carb = 'Carburetors'),
          n          = FALSE,
          perc_digits = 0,
          bg         = rgb(.2, .1, .2, .3))

c-hill-mdrc/QCmemo documentation built on July 25, 2020, 12:48 a.m.