Adds a column with overall summary statistics to tables created by tbl_summary, tbl_svysummary, tbl_continuous or tbl_custom_summary.

add_overall(x, ...)

# S3 method for tbl_summary
add_overall(
  x,
  last = FALSE,
  col_label = NULL,
  statistic = NULL,
  digits = NULL,
  ...
)

# S3 method for tbl_svysummary
add_overall(
  x,
  last = FALSE,
  col_label = NULL,
  statistic = NULL,
  digits = NULL,
  ...
)

# S3 method for tbl_continuous
add_overall(
  x,
  last = FALSE,
  col_label = NULL,
  statistic = NULL,
  digits = NULL,
  ...
)

# S3 method for tbl_custom_summary
add_overall(
  x,
  last = FALSE,
  col_label = NULL,
  statistic = NULL,
  digits = NULL,
  ...
)

Arguments

x

Object with class tbl_summary from the tbl_summary function, object with class tbl_svysummary from the tbl_svysummary function, object with class tbl_continuous from the tbl_continuous function or object with class tbl_custom_summary from the tbl_custom_summary function.

...

Not used

last

Logical indicator to display overall column last in table. Default is FALSE, which will display overall column first.

col_label

String indicating the column label. Default is "**Overall**, N = {N}"

statistic

Override the statistic argument in initial tbl_* function. call. Default is NULL.

digits

Override the digits argument in initial tbl_* function call. Default is NULL.

Value

A tbl_* of same class as x

Example Output

Example 1

Example 2

Example 3

Author

Daniel D. Sjoberg

Examples

# \donttest{
# Example 1 ----------------------------------
tbl_overall_ex1 <-
  trial %>%
  tbl_summary(include = c(age, grade), by = trt) %>%
  add_overall()

# Example 2 ----------------------------------
tbl_overall_ex2 <-
  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 ----------------------------------
tbl_overall_ex3 <-
  trial %>%
  tbl_continuous(
    variable = age,
    by = trt,
    include = grade
  ) %>%
  add_overall(last = TRUE)
# }