tbl_continuous() summarizes a continuous variable within the levels of
one or more categorical variables, e.g. the median age by tumor grade. The
categorical variables form the rows of the table, one row per level, and
the cells hold statistics of the continuous variable. The interface is
that of gtsummary::tbl_continuous().
Usage
tbl_continuous(
data,
variable,
include = everything(),
digits = NULL,
by = NULL,
statistic = everything() ~ "{median} ({p25}, {p75})",
label = NULL,
value = NULL
)Arguments
- data
(
data.frame)
A data frame.- variable
(selector)
A single column ofdata: the continuous variable to summarize. It does not appear as a row of the table; its label opens the footnote, e.g."Age: Median (Q1, Q3)".- include
(selector)
The categorical variables that form the rows of the table. Default iseverything(); thebyvariable andvariableare never summarized.- digits
(formula-list)
How the statistics are rounded: integers or formatting functions, keyed by theincludevariables. When not specified, the defaults are guessed from the values ofvariablebyassign_summary_digits().- by
(selector)
A single column ofdata. The statistics are stratified by its levels, one column per level. Rows with a missingbyvalue are dropped with a message. Default isNULL.- statistic
(formula-list)
The statistics shown for eachincludevariable, as a string with statistic names in curly braces. The statistics describevariable, so the continuous statistics oftbl_summary()are available:{median},{mean},{sd},{var},{min},{max},{sum},{p##}percentiles, the missing-data statistics, and the name of any function of one argument. Default iseverything() ~ "{median} ({p25}, {p75})".- label
(formula-list)
Variable labels. Labels of theincludevariables title their row groups; the label ofvariablechanges the footnote. The default for each variable is itslabelattribute, or the column name when there is none.- value
(formula-list)
The level of anincludevariable to show on a single row, e.g.value = list(grade = "III"). Default isNULL, which shows every level.
See also
add_p_continuous for the p-values of a tbl_continuous table,
and add_overall() and inline_text(), which also work on them.
Other table builders:
tbl_cross(),
tbl_custom_summary(),
tbl_likert(),
tbl_merge(),
tbl_regression(),
tbl_stack(),
tbl_strata(),
tbl_strata_nested_stack(),
tbl_summary(),
tbl_survfit(),
tbl_uvregression(),
tbl_wide_summary()
Examples
# Example 1 ----------------------------------
# median age by tumor grade
trial |>
tbl_continuous(variable = age, include = grade)
# Example 2 ----------------------------------
# stratified by treatment, with a custom statistic
trial |>
tbl_continuous(
variable = age,
by = trt,
include = c(grade, stage),
statistic = ~"{mean} ({sd})",
digits = ~1
)
# Example 3 ----------------------------------
# a single row per variable with `value`
trial |>
tbl_continuous(
variable = age,
by = trt,
include = c(grade, response),
value = list(grade = "III"),
label = list(grade = "Grade III")
)