[Experimental] Summarize a continuous variable by one or more categorical variables

tbl_continuous(
  data,
  variable,
  include = everything(),
  digits = NULL,
  by = NULL,
  statistic = NULL,
  label = NULL
)

Arguments

data

A data frame

variable

Variable name of the continuous column to be summarized

include

variables to include in the summary table. Default is everything()

digits

List of formulas specifying the number of decimal places to round continuous summary statistics. If not specified, an appropriate number of decimals to round statistics will be guessed based on the the variable's distribution.

by

A column name (quoted or unquoted) in data. Summary statistics will be calculated separately for each level of the by variable (e.g. by = trt). If NULL, summary statistics are calculated using all observations. To stratify a table by two or more variables, use tbl_strata()

statistic

List of formulas specifying types of summary statistics to display for each variable. The default is everything() ~ {median} ({p25}, {p75})

label

List of formulas specifying variables labels, e.g. list(age ~ "Age", stage ~ "Path T Stage"). If a variable's label is not specified here, the label attribute (attr(data$age, "label")) is used. If attribute label is NULL, the variable name will be used.

Value

a gtsummary table

Example Output

Example 1

Example 2

See also

Review list, formula, and selector syntax used throughout gtsummary

Other tbl_continuous tools: add_overall(), add_p.tbl_continuous()

Examples

# Example 1 ----------------------------------
tbl_continuous_ex1 <-
  tbl_continuous(
    data = trial,
    variable = age,
    by = trt,
    include = grade
  )

# Example 2 ----------------------------------
tbl_continuous_ex2 <-
  tbl_continuous(
    data = trial,
    variable = age,
    include = c(trt, grade)
  )