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 abyvariable.- last
(
scalar logical)
Whether to display the overall column last in the table. Default isFALSE, 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 thestatisticargument of the originaltbl_summary()call for the overall column only. Default isNULL.- digits
(formula-list)
Overrides thedigitsargument of the originaltbl_summary()call for the overall column only. Default isNULL.- ...
Not used.
See also
Other add statistics:
add_ci(),
add_difference(),
add_difference_row(),
add_n(),
add_p(),
add_p_continuous,
add_q(),
add_stat(),
add_stat_label(),
tests
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}")