Skip to contents

Quick helper function to easily transpose gtsummary::tbl_summary tables. Best used in conjunction with WAACHShelp::waachs_table.

Usage

transpose_tblsum(tbl, ...)

Arguments

tbl

tbl_summary input (of class c("tbl_summary", "gtsummary")).

...

Other parameters (not currently in use).

Value

data.frame with transposed summary table.

Examples

mtcars %>%
  mutate(cyl = as_factor(cyl)) %>%
  select(cyl, mpg, disp, hp, wt, am) %>%
  tbl_summary(by = cyl) %>%
  modify_header(label ~ "cyl") %>% # Re-label "Characteristic" by stratification variable ("cy")
  transpose_tblsum() %>%
  waachs_table()

cyl

mpg

disp

hp

wt

am

4 (N = 11)

26.0 (22.8, 30.4)

108 (79, 121)

91 (65, 97)

2.20 (1.84, 2.78)

8 (73%)

6 (N = 7)

19.7 (18.1, 21.0)

168 (160, 225)

110 (110, 123)

3.22 (2.77, 3.44)

3 (43%)

8 (N = 14)

15.2 (14.3, 16.4)

351 (301, 400)

193 (175, 245)

3.76 (3.52, 4.07)

2 (14%)