2

Update to clarify and show intention:

The related question is here tbl_merge: sort variables alphabetically in merged tbl_regression models {gtsummary} and @Daniel D. Sjoberg already provided the correct and professional answer.

But I want to try if this is possible:

x <- tbl_merge(list(t1, t2, t3 ,t4))

y <- x %>% 
  tbl_split(variables = c(age, ttdeath, response, death, stage, grade)) 

With this code I split the table into one row tables:

y[[1]]

enter image description here

y[[2]]

enter image description here

and so on.....

Now: I want to remove each footnote and header and merge them in a defined order together. In essence it is the reversal of spliting?!

Thanks for your time and energy!

First question:

With the tbl_regression() function from gtsummary we can make a table.

By adding modify_footnote(everything() ~ NA, abbreviation = TRUE) we can omit footnotes.

like here: from:supress confidence interval footnote in tbl_regression

library(dplyr)
library(gtsummary)

my_table <-
  lm(mpg ~ disp, mtcars) %>%
  tbl_regression(exponentiate = FALSE) %>%
  modify_footnote(everything() ~ NA, abbreviation = TRUE)
my_table

Result:

enter image description here

My question:

How can I remove the header part of this table to get this output:

enter image description here

If possible it should be possible with modify_header or modify_table_styling()?!

There is a rationale behind.

The ultimate goal is to split each element of a gtsummary table Split long gtsummary() table to n smaller tables and rearrange them in a given order tbl_merge: sort variables alphabetically in merged tbl_regression models {gtsummary}

Daniel D. Sjoberg
  • 8,820
  • 2
  • 12
  • 28
TarJae
  • 72,363
  • 6
  • 19
  • 66
  • 1
    There is no way to remove a header from a gtusmmary table with a gtsummary function. You can convert the gtsummary table to a gt object with `as_gt()`, and use `gt::tab_options(column_labels.hidden=)` to hide the column labels/headers. But then you can't combine the individual tables back together. If you update the post with an example of what you'd like in the end, perhaps I can guide you more on how to get what you're after? – Daniel D. Sjoberg Dec 19 '21 at 13:57
  • Thank you. Please see my update. But do not take to much time with it. It was just an idea! – TarJae Dec 19 '21 at 14:11
  • 1
    Once you've split your table, you can re-assemble it with `tbl_stack()`. No need to worry about the headers and footnotes...they will work themselves out. `tbl_stack(list(y[[2)]], y[[1)]])` – Daniel D. Sjoberg Dec 19 '21 at 19:10
  • 1
    Oh that is wonderful. Please share this as answer it is exactly what I was looking for! – TarJae Dec 19 '21 at 19:13

2 Answers2

1

A simple approach using the huxtable backend:

ht <- as_hux_table(my_table)
ht <- ht[2,] # just row 2

# and to bind multiple huxtables together, do e.g.
rbind(ht, ht2, ht3)

After this you can edit the style appropriately using huxtable functions.

dash2
  • 2,024
  • 6
  • 15
  • That is wonderful an new for me. Thank you a lot. Do you know if it is possible to get something similiar to gt_summary table. – TarJae Dec 19 '21 at 18:38
  • 1
    That is a gtsummary table. gtsummary uses huxtable (or gt, or other packages) as a backend. If you want the header rows, then just take `ht[1,]` and `rbind` it to the top. – dash2 Dec 20 '21 at 12:53
  • Ok. I see. Thank you for sharing! – TarJae Dec 20 '21 at 13:49
1

Once you've split your table, you can re-assemble it with tbl_stack(). No need to worry about the headers and footnotes...they will work themselves out. tbl_stack(list(y[[2)]], y[[1)]]).

Daniel D. Sjoberg
  • 8,820
  • 2
  • 12
  • 28