如何重新排列 gtsummary 或 flextable 中的列?

问题描述

关于这个答案[置信区间] (https://stackoverflow.com/a/66891473/13734451), 如何重新排列 gtsummary 或 flextable 中的列?有一种方法可以使用 gt 包(如下所示)来做到这一点,但这不会与 Word 女士结合。有线索吗?

final_tbl %>% as_gt() %>%
  cols_move(
    columns = vars(Male_ci),after = vars(stat_1)
  )

解决方法

这是一个移动 gtsummary 对象列的示例。此脚本将 p.value 列移到 label 列之后

library(gtsummary)
packageVersion("gtsummary")
#> '1.4.0'

# build table
tbl <-
  trial %>%
  select(age,trt) %>%
  tbl_summary(by = trt,missing = "no") %>%
  add_p() 

# move p.value column
tbl %>%
  modify_table_body(~.x %>% dplyr::relocate(p.value,.after = label))

enter image description here