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) |
48.2 (38.2, 55.3) |
44.9 (39.1, 54.4) |
49.3 (34.0, 56.1) |
| Min, Max |
26.0, 61.8 |
37.2, 61.8 |
26.0, 58.5 |
| sex |
|
|
|
| F |
7 (35%) |
3 (43%) |
4 (57%) |
| M |
13 (65%) |
7 (54%) |
6 (46%) |