## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## 
## Attaching package: 'flextable'
## 
## 
## The following object is masked from 'package:gtsummary':
## 
##     continuous_summary
## 
## 
## The following object is masked from 'package:purrr':
## 
##     compose
## 
## 
## Suggested APA citation: Thériault, R. (2023). rempsyc: Convenience functions for psychology. 
## Journal of Open Source Software, 8(87), 5466. https://doi.org/10.21105/joss.05466
## 
## 
## Attaching package: 'ggpubr'
## 
## 
## The following objects are masked from 'package:flextable':
## 
##     border, font, rotate

Results

#summarises the cars in the mtcars dataset by transmission.

mtcarsSummaryTbl <- mtcars %>% 
  tbl_summary(by = am) %>% 
  modify_header(
    stat_1 = "**Automatic**, N = {n}",
    stat_2 = "**Manual**, N = {n}",
  ) %>% 
  add_overall()
mtcarsSummaryTbl
Characteristic Overall
N = 32
1
Automatic, N = 191 Manual, N = 131
mpg 19.2 (15.4, 22.8) 17.3 (14.7, 19.2) 22.8 (21.0, 30.4)
cyl


    4 11 (34%) 3 (16%) 8 (62%)
    6 7 (22%) 4 (21%) 3 (23%)
    8 14 (44%) 12 (63%) 2 (15%)
disp 196 (121, 334) 276 (168, 360) 120 (79, 160)
hp 123 (96, 180) 175 (110, 205) 109 (66, 113)
drat 3.70 (3.08, 3.92) 3.15 (3.07, 3.70) 4.08 (3.85, 4.22)
wt 3.33 (2.54, 3.65) 3.52 (3.44, 3.85) 2.32 (1.94, 2.78)
qsec 17.71 (16.89, 18.90) 17.82 (17.05, 19.44) 17.02 (16.46, 18.61)
vs 14 (44%) 7 (37%) 7 (54%)
gear


    3 15 (47%) 15 (79%) 0 (0%)
    4 12 (38%) 4 (21%) 8 (62%)
    5 5 (16%) 0 (0%) 5 (38%)
carb


    1 7 (22%) 3 (16%) 4 (31%)
    2 10 (31%) 6 (32%) 4 (31%)
    3 3 (9.4%) 3 (16%) 0 (0%)
    4 10 (31%) 7 (37%) 3 (23%)
    6 1 (3.1%) 0 (0%) 1 (7.7%)
    8 1 (3.1%) 0 (0%) 1 (7.7%)
1 Median (Q1, Q3); n (%)