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) |
46.6 (35.4, 57.5) |
48.9 (35.6, 57.4) |
40.9 (34.9, 57.7) |
| Min, Max |
29.5, 71.0 |
29.5, 69.1 |
34.0, 71.0 |
| sex |
|
|
|
| F |
8 (40%) |
3 (38%) |
5 (63%) |
| M |
12 (60%) |
7 (58%) |
5 (42%) |