Skip to contents

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 of data: 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 is everything(); the by variable and variable are never summarized.

digits

(formula-list)
How the statistics are rounded: integers or formatting functions, keyed by the include variables. When not specified, the defaults are guessed from the values of variable by assign_summary_digits().

by

(selector)
A single column of data. The statistics are stratified by its levels, one column per level. Rows with a missing by value are dropped with a message. Default is NULL.

statistic

(formula-list)
The statistics shown for each include variable, as a string with statistic names in curly braces. The statistics describe variable, so the continuous statistics of tbl_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 is everything() ~ "{median} ({p25}, {p75})".

label

(formula-list)
Variable labels. Labels of the include variables title their row groups; the label of variable changes the footnote. The default for each variable is its label attribute, or the column name when there is none.

value

(formula-list)
The level of an include variable to show on a single row, e.g. value = list(grade = "III"). Default is NULL, which shows every level.

Value

A table of class c("tbl_continuous", "ltsummary").

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") )