我会将 N 和 % 的值拆分为两个单独的列,即 N 和 % 列
library(gtsummary)
trial %>%
select(response, grade) %>%
tbl_summary()
Run Code Online (Sandbox Code Playgroud)
最简单的方法是使用tbl_merge()构建两个表(一个使用 N,另一个使用 %)。下面举例!
library(gtsummary)
#> #BlackLivesMatter
library(tidyverse)
tbl <-
# iterate over these two statistics
c("{n} / {N}", "{p}%") %>%
# build tbl_summary using each of the stats
map(
~trial %>%
select(response, grade) %>%
tbl_summary(
statistic = all_categorical() ~ .x,
missing = "no"
)
) %>%
# merge the two tables together
tbl_merge() %>%
# some formatting to make it cute
modify_spanning_header(everything() ~ NA) %>%
modify_footnote(everything() ~ NA) %>%
modify_header(list(stat_0_1 ~ "**n / N**", stat_0_2 ~ "**percent**"))
Run Code Online (Sandbox Code Playgroud)
由reprex 包(v2.0.0)创建于 2021-08-06
| 归档时间: |
|
| 查看次数: |
1096 次 |
| 最近记录: |