英文:
How to write a gtsummary with CI and overall column in last column
问题
I would like to write a summary with confidence intervals for categorical variables and an overall column at the end of the table.
However using the following code, the overall column is placed at the front:
library(gtsummary)
library(tidyverse)
trial %>%
tbl_summary(
by = trt,
include = "stage") %>%
add_overall(last = TRUE)%>%
add_ci()
Why is the overall column at the beginning, even though I set last = TRUE
?
英文:
I would like to write a summary with confidence intervals for categorical variables and an overall column at the end of the table.
However using the following code, the overall column is placed at the front:
library(gtsummary)
library(tidyverse)
trial %>%
tbl_summary(
by = trt,
include = "stage") %>%
add_overall(last = TRUE)%>%
add_ci()
Why is the overall column at the beginning, even though I set last = TRUE
?
答案1
得分: 0
以下是重新排列gtsummary表格列的解决方案:
library(gtsummary)
trial %>%
tbl_summary(
by = trt,
include = "stage"
) %>%
add_overall(last = TRUE) %>%
add_ci() %>%
modify_table_body(
~dplyr::relocate(.x, stat_0, ci_stat_0, .after = last_col() )
) %>%
as_kable()
特征 | 药物 A, N = 98 | 95% 置信区间 | 药物 B, N = 102 | 95% 置信区间 | 总体, N = 200 | 95% 置信区间 |
---|---|---|---|---|---|---|
T 分期 | ||||||
T1 | 28 (29%) | 20%, 39% | 25 (25%) | 17%, 34% | 53 (27%) | 21%, 33% |
T2 | 25 (26%) | 17%, 35% | 29 (28%) | 20%, 38% | 54 (27%) | 21%, 34% |
T3 | 22 (22%) | 15%, 32% | 21 (21%) | 13%, 30% | 43 (22%) | 16%, 28% |
T4 | 23 (23%) | 16%, 33% | 27 (26%) | 18%, 36% | 50 (25%) | 19%, 32% |
创建于2023-06-15,使用 reprex v2.0.2
我在这里 https://github.com/ddsjoberg/gtsummary/issues/1525 提交了一个关于gtsummary的错误报告。
英文:
See below for a solution to re-order columns in a gtsummary table.
library(gtsummary)
trial %>%
tbl_summary(
by = trt,
include = "stage") %>%
add_overall(last = TRUE) %>%
add_ci() %>%
modify_table_body(
~dplyr::relocate(.x, stat_0, ci_stat_0, .after = last_col() )
) %>%
as_kable()
Characteristic | Drug A, N = 98 | 95% CI | Drug B, N = 102 | 95% CI | Overall, N = 200 | 95% CI |
---|---|---|---|---|---|---|
T Stage | ||||||
T1 | 28 (29%) | 20%, 39% | 25 (25%) | 17%, 34% | 53 (27%) | 21%, 33% |
T2 | 25 (26%) | 17%, 35% | 29 (28%) | 20%, 38% | 54 (27%) | 21%, 34% |
T3 | 22 (22%) | 15%, 32% | 21 (21%) | 13%, 30% | 43 (22%) | 16%, 28% |
T4 | 23 (23%) | 16%, 33% | 27 (26%) | 18%, 36% | 50 (25%) | 19%, 32% |
<sup>Created on 2023-06-15 with reprex v2.0.2</sup>
I filed a bug report with gtsummary here https://github.com/ddsjoberg/gtsummary/issues/1525
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论