Skip to contents

tbl_wide_summary() is similar to tbl_summary(), but places the summary statistics wide, in separate columns. All included variables must be of the same summary type: all continuous summaries, or all categorical summaries (which include dichotomous variables).

Usage

tbl_wide_summary(
  data,
  label = NULL,
  statistic = switch(type[[1]], continuous = c("{median}", "{p25}, {p75}"), c("{n}",
    "{p}%")),
  digits = NULL,
  type = NULL,
  value = NULL,
  sort = all_categorical(FALSE) ~ "alphanumeric",
  include = everything()
)

Arguments

data

(data.frame)
A data frame.

label

(formula-list)
Variable labels, e.g. list(age = "Age, years"). The default for each variable is its label attribute, or the column name when there is none.

statistic

(character)
The statistics to present; each element of the vector becomes a column of the table. Default is c("{median}", "{p25}, {p75}") for continuous summaries and c("{n}", "{p}%") for categorical and dichotomous summaries.

digits

(formula-list)
How the statistics are rounded: integers or formatting functions. When not specified, the defaults come from assign_summary_digits().

type

(formula-list)
The summary type, "continuous", "categorical" or "dichotomous"; the default comes from assign_summary_type().

value

(formula-list)
The level of a variable to show on a single row, e.g. value = list(response = 1). Default is NULL.

sort

(formula-list)
"alphanumeric" (the default) or "frequency" ordering of categorical levels.

include

(selector)
Variables to include. Default is everything().

Value

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

Examples

# Example 1 ----------------------------------
trial |>
  tbl_wide_summary(include = c(response, grade))
# Example 2 ---------------------------------- trial |> tbl_wide_summary(include = c(age, marker))