Summarize a continuous variable by one or more categorical variables
tbl_continuous(
data,
variable,
include = everything(),
digits = NULL,
by = NULL,
statistic = everything() ~ "{median} ({p25}, {p75})",
label = NULL,
value = NULL
)
(data.frame
)
A data frame.
(tidy-select
)
A single column from data
. Variable name of the continuous column to be summarized.
(tidy-select
)
Variables to include in the summary table. Default is everything()
.
(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.
(tidy-select
)
A single column from data
. Summary statistics will be stratified by this variable.
Default is NULL
.
(formula-list-selector
)
Specifies summary statistics to display for each variable. The default is
everything() ~ "{median} ({p25}, {p75})"
.
(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.
(formula-list-selector
)
Supply a value to display a variable on a single row, printing the
results for the variable associated with the value (similar to a
'dichotomous'
display in tbl_summary()
).
a gtsummary table
# Example 1 ----------------------------------
tbl_continuous(
data = trial,
variable = age,
by = trt,
include = grade
)
Characteristic
Drug A
N = 981
Drug B
N = 1021
1 Age: Median (Q1, Q3)
# Example 2 ----------------------------------
trial |>
dplyr::mutate(all_subjects = 1) |>
tbl_continuous(
variable = age,
statistic = ~"{mean} ({sd})",
by = trt,
include = c(all_subjects, stage, grade),
value = all_subjects ~ 1,
label = list(all_subjects = "All Subjects")
)
Characteristic
Drug A
N = 981
Drug B
N = 1021
1 Age: Mean (SD)