Skip to contents

Adds a column with overall summary statistics to a table created by tbl_summary(by =), tbl_continuous(by =), tbl_custom_summary(by =), tbl_hierarchical(by =) or tbl_hierarchical_count(by =), summarizing every observation regardless of its by level. The column uses the statistics and digits of the rest of the table unless statistic or digits say otherwise. On a tbl_hierarchical_count() table without a denominator the default header is plain "**Overall**".

Usage

add_overall(
  x,
  last = FALSE,
  col_label = "**Overall**  \nN = {style_number(N)}",
  statistic = NULL,
  digits = NULL,
  ...
)

Arguments

x

(tbl_summary, tbl_continuous, tbl_custom_summary, tbl_hierarchical, tbl_hierarchical_count)
A table with a by variable.

last

(scalar logical)
Whether to display the overall column last in the table. Default is FALSE, which displays it first.

col_label

(string)
The column header. Default is "**Overall** \nN = {style_number(N)}", where {N} is the total number of observations.

statistic

(formula-list)
Overrides the statistic argument of the original tbl_summary() call for the overall column only. Default is NULL.

digits

(formula-list)
Overrides the digits argument of the original tbl_summary() call for the overall column only. Default is NULL.

...

Not used.

Value

A table of class c("tbl_summary", "ltsummary") with a stat_0 column.

Examples

# Example 1 ----------------------------------
trial |>
  tbl_summary(include = c(age, grade), by = trt) |>
  add_overall()
# Example 2 ---------------------------------- # different statistics in the overall column, placed last trial |> tbl_summary( include = grade, by = trt, percent = "row", statistic = ~"{p}%", digits = ~1 ) |> add_overall( last = TRUE, statistic = ~"{p}% (n={n})", digits = ~c(1, 0) )
# Example 3 ---------------------------------- # a custom header for the overall column trial |> tbl_summary(include = c(age, response), by = trt) |> add_overall(col_label = "**All patients** \nN = {N}")