Default summary function in pt_demographics for continuous variables

dem_cont_fun(
  value = seq(1, 5),
  name = "",
  ...,
  fmt = sig,
  digits = 3,
  maxex = 5
)

Arguments

value

a vector or column to summarize

name

the name of the variable currently being summarized

...

other arguments passed to fmt

fmt

a function to format the numbers in the continuous data summary

digits

passed to fmt

maxex

passed to fmt

Value

A tibble with one row and three columns:

  1. Mean (SD) the mean and standard deviation of value

  2. Min / Max the range of the value

  3. Missing the number of missing values

Details

The summary function should have these arguments:

  • value the data to summarize

  • name the name of the data column being summarized; length 1

  • ... absorbs other arguments that might get passed

These are the important arguments; name is not required as a formal argument but ... is. The idea is that the custom summary function receives the data to be summarized, the name of that data, and other arguments. Since you are in charge of the function, you can make decisions about both summaries and the formatting of those summaries inside the function you are maintaining. Notice that dem_cont_fun also contains arguments fmt (a formatting function) and digits and maxex (arguments to be passed to fmt). This means that you can have your summary function call the default summary function but with different formatting parameters.

The summary function should return a data frame, with summary statistics in the columns.

Examples

pmtables:::dem_cont_fun(value = seq(1,7), digits = 2)
#> # A tibble: 1 × 3 #> `Mean (SD)` `Min / Max` Missing #> <chr> <chr> <chr> #> 1 4.0 (2.2) 1 / 7 0