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 isFALSE
, 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 initialtbl_*
function call. Default isNULL
.- digits
(
formula-list-selector
)
Override the digits argument in initialtbl_*
function call. Default isNULL
.
Examples
# Example 1 ----------------------------------
trial |>
tbl_summary(include = c(age, grade), by = trt) |>
add_overall()
Characteristic
Overall
N = 2001
Drug A
N = 981
Drug B
N = 1021
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 = 981
Drug B
N = 1021
Overall
N = 2002
1 %
2 % (n=n)
# Example 3 ----------------------------------
trial |>
tbl_continuous(
variable = age,
by = trt,
include = grade
) |>
add_overall(last = TRUE)
Characteristic
Drug A
N = 981
Drug B
N = 1021
Overall
N = 2001
1 Age: Median (Q1, Q3)