summaryTable: Generate a summary table

Description Usage Arguments Value Examples

View source: R/QCMemo_script.R

Description

The function summaryTable is roughly analogous to PROC MEANS in SAS. The functionality is slightly more limited than PROC MEANS, but the results are aesthetically similar.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
summaryTable(
  inputds,
  class,
  var,
  varnames = c(class, var),
  n = TRUE,
  nmiss = TRUE,
  percent = TRUE,
  mean = TRUE,
  min = TRUE,
  max = TRUE,
  perc_digits = 1,
  digits = 1,
  bg = "aliceblue",
  date = FALSE
)

Arguments

inputds

A dataset to be summarized.

class

A vector of names indicating variables to be used for classification.

var

The name of the analysis variable.

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?

nmiss

Logical. Should number of missing values be displayed?

percent

Logical. Should percents be displayed?

mean

Logical. Should means be displayed?

min

Logical. Should minima be displayed?

max

Logical. Should maxima be displayed?

perc_digits

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

digits

A number indicating how many decimal places should be displayed for the mean, minimum, and maximum

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.

date

Logical. Is the analysis variable a date?

Value

A flextable object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Simple table with one class variable
summaryTable(inputds     = mtcars,
             class       = 'cyl',
             var         = 'mpg',
             varnames    = list(cyl = 'Cylinders', mpg = 'Miles per gallon'))

# Two class variables and customization through additional parameters
summaryTable(inputds     = mtcars,
             class       = c('cyl', 'gear'),
             var         = 'mpg',
             varnames    = list(cyl  = 'Cylinders',
                                gear = 'Number of forward gears',
                                mpg  = 'Miles per gallon'),
             nmiss       = FALSE,
             perc_digits = 0,
             digits      = 2,
             bg          = 'olivedrab1')

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