更改 gtsummary::tbl_merge 中的空单元格

Change empty cells in gtsummary::tbl_merge

我合并了两个不同行的表格,结果单元格为空。我想用明确的“缺失”或“---”替换空单元格(这也可能是在 tbl_merge 中实现的未来功能)。我尝试使用 superstar 函数 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()
特征 药物A, N = 98 药物 B, N = 102 药物A, N = 98 药物 B, N = 102
年龄 46 (37, 59) 48 (39, 56)
未知 7 4
标记级别 (ng/mL) 0.84 (0.24, 1.57) 0.52 (0.19, 1.20)
未知 6 4
T台
T1 28 (29%) 25 (25%)
T2 25 (26%) 29 (28%)
T3 22 (22%) 21 (21%)
T4 23 (23%) 27 (26%)
年级
35 (36%) 33 (32%)
32 (33%) 36 (35%)
31 (32%) 33 (32%)
肿瘤反应 28 (29%) 33 (34%) 28 (29%) 33 (34%)
未知 3 4 3 4
患者死亡 52 (53%) 60 (59%)
个月到 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-07-30 创建

你说得对,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"
  )