Learn R Programming

dtlg (version 0.0.2)

calc_desc: Calculate descriptive summary statistics for a numeric variable

Description

calc_desc() summarises a numeric variable (target) by another (treat) and reports summary statistics in clinical trial reporting format. The following statistics are calculated for target, per group, i.e. by variable treat levels:

  • n: number of observations

  • Mean (SD): mean and standard deviation of target

  • Median: median of target

  • Min, Max: minimum and maximum of target

  • Missing: number of missing target values

Usage

calc_desc(
  dt,
  target,
  target_name = target,
  treat,
  indent = nbsp(n = 4L),
  pct_dec = 1
)

Value

A list containing a data.table formatted as follows:

  • First column is named stats and contains the target variable name indicated in target in the first row. Subsequent rows contain the summarised statistics labels.

  • Other columns are for the levels of the grouping variable (treat).

  • All columns are of character type.

This table is structured for easy integration with Shiny output widgets.

Arguments

dt

A data.frame containing, at least, the variables indicated in target and treat.

target

Target variable passed as a string for which summary statistics are to be calculated.

target_name

Heading for the target variable as a string. Defaults to target.

treat

A string indicating the grouping variable, e.g. the variable specifying the treatment population.

indent

A string to be used as indentation of summary statistics labels. Defaults to four HTML non-breaking spaces ( ).

pct_dec

Decimal places for reported figures.

Examples

Run this code
# Calculate summary statistics for the age of the subjects in each region.
calc_stats(dt = adsl, "AGE", treat = "REGION1")[[1]]

# Calculate summary statistics for biomarker 1 in each of the three arms
# (`ARM`).
calc_stats(dt = adsl, "BMRKR1", treat = "ARM")[[1]]

Run the code above in your browser using DataLab