【问题标题】:Change empty cells in gtsummary::tbl_merge更改 gtsummary::tbl_merge 中的空单元格
【发布时间】:2021-07-30 15:40:33
【问题描述】:

我合并了两个不同行的表格,导致单元格为空。我想用明确的“缺失”或“---”替换空单元格(这也可能是在tbl_merge 中实现的未来功能)。我尝试使用超级明星功能modify_table_styling,但找不到行。我试过everything()is.na(estimate)。另外,请注意,我实际上在 tbl_merge 上有一个 tbl_merge,所以我的 my_df$table_body 在其中查找行标识符更加复杂。

感谢您的帮助!

library(gtsummary)
library(dplyr)

tbl_dense <-
  trial %>%
  tbl_summary(by = trt)

tbl_sparse <-
  trial %>%
  select(trt, response) %>%
  tbl_summary(by = trt)

tbl_merge(list(tbl_dense, tbl_sparse)) %>% 
  as_kable()
Characteristic Drug A, N = 98 Drug B, N = 102 Drug A, N = 98 Drug B, N = 102
Age 46 (37, 59) 48 (39, 56)
Unknown 7 4
Marker Level (ng/mL) 0.84 (0.24, 1.57) 0.52 (0.19, 1.20)
Unknown 6 4
T Stage
T1 28 (29%) 25 (25%)
T2 25 (26%) 29 (28%)
T3 22 (22%) 21 (21%)
T4 23 (23%) 27 (26%)
Grade
I 35 (36%) 33 (32%)
II 32 (33%) 36 (35%)
III 31 (32%) 33 (32%)
Tumor Response 28 (29%) 33 (34%) 28 (29%) 33 (34%)
Unknown 3 4 3 4
Patient Died 52 (53%) 60 (59%)
Months to Death/Censor 23.5 (17.4, 24.0) 21.2 (14.6, 24.0)
  
# Likely with this do-it-all function
# modify_table_styling(
#   column = estimate,
#   rows = is.na(estimate), # Not sure how to select rows
#   missing_symbol = "MISSING"
# )

reprex package (v2.0.0) 于 2021 年 7 月 30 日创建

【问题讨论】:

    标签: r gtsummary


    【解决方案1】:

    你是对的,modify_table_styling() 函数是要走的路。下面的例子!

    library(gtsummary)
    packageVersion("gtsummary")
    
    tbl_dense <-
      trial %>%
      tbl_summary(by = trt)
    
    tbl_sparse <-
      trial %>%
      select(trt, response) %>%
      tbl_summary(by = trt)
    
    tbl <-
      tbl_merge(list(tbl_dense, tbl_sparse)) %>%
      modify_table_styling(
        columns = everything(),
        rows = !is.na(variable),
        missing_symbol = "MISSING"
      )
    

    【讨论】:

    • 谢谢!这适用于reprex,但我在我的实际(巨大)回归表上得到Error: C stack usage is too close to the limit。不幸的是,我认为这个问题超出了gtsummary 以及我的基本计算机知识的范围:/ Running R 4.1.0, RStudio 1.4.1717, gtsummary 1.4.2.900, macOS 11.4
    • gtsummary 表可以得到很大的数据回归模型,尤其是大型数据回归模型。您也许可以按顺序构建表格。当每个表都完成后,可以使用此功能来减小大小。 danieldsjoberg.com/bstfun/reference/gtsummary_butcher.html
    • 感谢您介绍该功能!我尝试减少每个单独的表,然后是组合表,虽然它从巨大的 200.1 Mb 减少到 20.6 Mb,但我仍然得到Error: C stack usage is too close to the limit。空单元格可以做到这一点,否则我将在 gtsummary 之外进行更改。
    猜你喜欢
    • 2022-11-08
    • 2021-05-26
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多