Learn R Programming

gtsummary (version 1.2.1)

modify_header: Modify column headers in gtsummary tables

Description

Column labels can be modified to include calculated statistics; e.g. the N can be dynamically included by wrapping it in curly brackets (following glue::glue syntax).

Usage

modify_header(x, stat_by = NULL, ..., text_interpret = c("md", "html"))

Arguments

x

gtsummary object, e.g. tbl_summary or tbl_regression

stat_by

String specifying text to include above the summary statistics stratified by a variable. Only use with stratified tbl_summary objects. The following fields are available for use in the headers:

  • {n} number of observations in each group,

  • {N} total number of observations,

  • {p} percentage in each group,

  • {level} the 'by' variable level,

  • "fisher.test" for a Fisher's exact test,

Syntax follows glue::glue, e.g. stat_by = "**{level}**, N = {n} ({style_percent(p)\%})". The by argument from the parent tbl_summary() cannot be NULL.

...

Specifies column label of any other column in .$table_body. Argument is the column name, and the value is the new column header (e.g. p.value = "Model P-values"). Use print(x$table_body) to see columns available.

text_interpret

indicates whether text will be interpreted as markdown ("md") or HTML ("html"). The text is interpreted with the gt package's md() or html() functions. The default is "md", and is ignored when the print engine is not gt.

Value

Function return the same class of gtsummary object supplied

Example Output

Example 1

Example 2

See Also

Other tbl_summary tools: add_n, add_overall, add_p, add_q.tbl_summary, add_stat_label, bold_italicize_labels_levels, bold_p.tbl_summary, inline_text.tbl_summary, sort_p.tbl_summary, tbl_summary

Other tbl_regression tools: add_global_p.tbl_regression, add_nevent.tbl_regression, bold_italicize_labels_levels, bold_p.tbl_regression, bold_p.tbl_stack, inline_text.tbl_regression, sort_p.tbl_regression, tbl_merge, tbl_regression, tbl_stack

Other tbl_uvregression tools: add_global_p.tbl_uvregression, add_nevent.tbl_uvregression, add_q.tbl_uvregression, bold_italicize_labels_levels, bold_p.tbl_stack, bold_p.tbl_uvregression, inline_text.tbl_uvregression, sort_p.tbl_uvregression, tbl_merge, tbl_stack, tbl_uvregression

Other tbl_survival tools: inline_text.tbl_survival, tbl_survival.survfit

Examples

Run this code
# NOT RUN {
tbl_col_ex1 <-
  trial[c("age", "grade", "response")] %>%
  tbl_summary() %>%
  modify_header(stat_0 = "**All Patients**, N = {N}")

tbl_col_ex2 <-
  trial[c("age", "grade", "response", "trt")] %>%
  tbl_summary(by = trt) %>%
  modify_header(
    stat_by = "**{level}**, N = {n} ({style_percent(p, symbol = TRUE)})"
  )
# }

Run the code above in your browser using DataLab