【问题标题】:Setting the Overall column to report column percentage in gtsummary设置总体列以报告 gtsummary 中的列百分比
【发布时间】:2021-08-24 12:53:42
【问题描述】:

我希望总体具有列百分比,而其他列报告行百分比。怎么办呢。提前致谢。

library(gtsummary)
library(dplyr)


trial %>%
  select(age, grade, response, trt) %>%
  tbl_summary(by=trt, percent = "row",
              type = response ~ "categorical",
              missing = "no") %>%
  add_overall()

【问题讨论】:

    标签: gtsummary


    【解决方案1】:

    add_overall() 的结果将始终与tbl_summary() 中的调用一致。要获得您所追求的,请构建两个表并将它们合并。下面的例子!

    library(gtsummary)
    
    tbl_row_percent <- 
      trial %>%
      select(age, grade, response, trt) %>%
      tbl_summary(by=trt, percent = "row",
                  type = response ~ "categorical",
                  missing = "no") 
    
    tbl_col_percent <- 
      trial %>%
      select(age, grade, response) %>%
      tbl_summary(type = response ~ "categorical",
                  missing = "no") %>%
      modify_header(all_stat_cols() ~ "**Overall**, N = {N}")
    
    tbl_final <-
      tbl_merge(list(tbl_col_percent, tbl_row_percent)) %>%
      modify_spanning_header(everything() ~ NA)
    

    reprex package (v2.0.1) 于 2021 年 8 月 24 日创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 2021-12-14
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多