Skip to contents

Summarize a continuous variable by one or more categorical variables

Usage

tbl_continuous(
  data,
  variable,
  include = everything(),
  digits = NULL,
  by = NULL,
  statistic = everything() ~ "{median} ({p25}, {p75})",
  label = NULL
)

Arguments

data

(data.frame)
A data frame.

variable

(tidy-select)
A single column from data. Variable name of the continuous column to be summarized.

include

(tidy-select)
Variables to include in the summary table. Default is everything().

digits

(formula-list-selector)
Specifies how summary statistics are rounded. Values may be either integer(s) or function(s). If not specified, default formatting is assigned via assign_summary_digits(). See below for details.

by

(tidy-select)
A single column from data. Summary statistics will be stratified by this variable. Default is NULL.

statistic

(formula-list-selector)
Specifies summary statistics to display for each variable. The default is everything() ~ "{median} ({p25}, {p75})".

label

(formula-list-selector)
Used to override default labels in summary table, e.g. list(age = "Age, years"). The default for each variable is the column label attribute, attr(., 'label'). If no label has been set, the column name is used.

Value

a gtsummary table

Examples

# Example 1 ----------------------------------
tbl_continuous(
  data = trial,
  variable = age,
  by = trt,
  include = grade
)
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
Grade

    I 46 (36, 60) 48 (42, 55)
    II 45 (31, 55) 51 (42, 58)
    III 52 (42, 61) 45 (36, 52)
1 Age: Median (Q1, Q3)
# Example 2 ---------------------------------- tbl_continuous( data = trial, variable = age, statistic = ~"{mean} ({sd})", by = trt, include = c(stage, grade) )
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
T Stage

    T1 44 (15) 50 (14)
    T2 50 (13) 46 (12)
    T3 49 (14) 50 (15)
    T4 45 (17) 44 (15)
Grade

    I 46 (16) 46 (15)
    II 45 (15) 50 (12)
    III 51 (13) 46 (15)
1 Age: Mean (SD)