The Overall column reports percentages for the overall cohort.
The group columns report row-wise percentages.
Usage
table_overall_and_group(d, name_groupvar, group_header = "**Group**")
Arguments
- d
data.frame. Dataset containing variables to summarize.
- name_groupvar
character(1). Name of the grouping variable (column
name) in d used to produce the grouped summary.
character(1). Label used as the tab spanner for the
grouped columns in the merged table.
Value
A gtsummary table object
Details
The function builds two tbl_summary objects: one for the overall
dataset (with the grouping column removed) and one stratified by the
specified grouping variable. It then merges them into a single table with
a custom tab spanner for the grouped columns.
Examples
df <- data.frame(
grp = rep(c("A","B"), each = 10),
age = rnorm(20, 50, 10),
sex = sample(c("M","F"), 20, TRUE)
)
table_overall_and_group(df, "grp")
#> Setting theme "language: en"
#> Setting theme "Compact"
| Characteristic |
Overall N = 20 |
Group
|
|---|
A n = 10 |
B n = 10 |
|---|
| age |
|
|
|
| Median (Q1, Q3) |
53.8 (46.8, 58.2) |
55.1 (47.6, 57.9) |
51.0 (46.1, 61.2) |
| Min, Max |
25.1, 68.7 |
42.3, 68.7 |
25.1, 66.5 |
| sex |
|
|
|
| F |
9 (45%) |
5 (56%) |
4 (44%) |
| M |
11 (55%) |
5 (45%) |
6 (55%) |