Skip to contents

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

Usage

add_overall(x, ...)

# S3 method for class 'tbl_summary'
add_overall(
  x,
  last = FALSE,
  col_label = "**Overall**  \nN = {style_number(N)}",
  statistic = NULL,
  digits = NULL,
  ...
)

# S3 method for class 'tbl_continuous'
add_overall(
  x,
  last = FALSE,
  col_label = "**Overall**  \nN = {style_number(N)}",
  statistic = NULL,
  digits = NULL,
  ...
)

# S3 method for class 'tbl_svysummary'
add_overall(
  x,
  last = FALSE,
  col_label = "**Overall**  \nN = {style_number(N)}",
  statistic = NULL,
  digits = NULL,
  ...
)

# S3 method for class 'tbl_custom_summary'
add_overall(
  x,
  last = FALSE,
  col_label = "**Overall**  \nN = {style_number(N)}",
  statistic = NULL,
  digits = NULL,
  ...
)

Arguments

x

(tbl_summary, tbl_svysummary, tbl_continuous, tbl_custom_summary)
A stratified 'gtsummary' table

...

These dots are for future extensions and must be empty.

last

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

col_label

(string)
String indicating the column label. Default is "**Overall** \nN = {style_number(N)}"

statistic

(formula-list-selector)
Override the statistic argument in initial tbl_* function call. Default is NULL.

digits

(formula-list-selector)
Override the digits argument in initial tbl_* function call. Default is NULL.

Value

A gtsummary of same class as x

Author

Daniel D. Sjoberg

Examples

# Example 1 ----------------------------------
trial |>
  tbl_summary(include = c(age, grade), by = trt) |>
  add_overall()
Characteristic Overall
N = 200
1
Drug A
N = 98
1
Drug B
N = 102
1
Age 47 (38, 57) 46 (37, 60) 48 (39, 56)
    Unknown 11 7 4
Grade


    I 68 (34%) 35 (36%) 33 (32%)
    II 68 (34%) 32 (33%) 36 (35%)
    III 64 (32%) 31 (32%) 33 (32%)
1 Median (Q1, Q3); n (%)
# Example 2 ---------------------------------- 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) )
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
Overall
N = 200
2
Grade


    I 51.5% 48.5% 100.0% (n=68)
    II 47.1% 52.9% 100.0% (n=68)
    III 48.4% 51.6% 100.0% (n=64)
1 %
2 % (n=n)
# Example 3 ---------------------------------- trial |> tbl_continuous( variable = age, by = trt, include = grade ) |> add_overall(last = TRUE)
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
Overall
N = 200
1
Grade


    I 46 (36, 60) 48 (42, 55) 47 (37, 56)
    II 45 (31, 55) 51 (42, 58) 49 (37, 57)
    III 52 (42, 61) 45 (36, 52) 47 (38, 58)
1 Age: Median (Q1, Q3)