想要将数字(小数)仅放入 tbl_summary 中单独的百分比列值。任何关于地图如何工作的分解教程?
Want to put digits(decimals) to ONLY the separate percentage column values in tbl_summary. Any break down tutorial on how map works?
我只想为百分比列添加小数
#分列
图书馆(gsummary)
图书馆(整洁宇宙)
tbl <-
c("{n}", "{p}%") %>% # iterate over these two statistics
# build tbl_summary using each of the stats
map(
~trial %>%
select(response, grade) %>%
tbl_summary(
statistic = all_categorical() ~ .x,
missing = "ifany",
digits = list(
all_categorical() ~ 1,
all_continuous() ~ 0
),
missing_text = "(Missing)"
)
) %>%
# 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**"))
您可以有条件地添加 digits=
值,具体取决于我们是汇总百分比还是计数。示例如下!
library(gtsummary)
tbl <-
c("{n}", "{p}%") %>% # iterate over these two statistics
# build tbl_summary using each of the stats
purrr::map(
~trial %>%
select(response, grade) %>%
tbl_summary(
statistic = all_categorical() ~ .x,
missing = "ifany",
digits = list(
all_categorical() ~ ifelse(.x == "{p}%", 1, 0),
all_continuous() ~ 0
),
missing_text = "(Missing)"
)
) %>%
# 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**"))
由 reprex package (v2.0.1)
于 2021-12-07 创建
我只想为百分比列添加小数
#分列 图书馆(gsummary) 图书馆(整洁宇宙)
tbl <-
c("{n}", "{p}%") %>% # iterate over these two statistics
# build tbl_summary using each of the stats
map(
~trial %>%
select(response, grade) %>%
tbl_summary(
statistic = all_categorical() ~ .x,
missing = "ifany",
digits = list(
all_categorical() ~ 1,
all_continuous() ~ 0
),
missing_text = "(Missing)"
)
) %>%
# 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**"))
您可以有条件地添加 digits=
值,具体取决于我们是汇总百分比还是计数。示例如下!
library(gtsummary)
tbl <-
c("{n}", "{p}%") %>% # iterate over these two statistics
# build tbl_summary using each of the stats
purrr::map(
~trial %>%
select(response, grade) %>%
tbl_summary(
statistic = all_categorical() ~ .x,
missing = "ifany",
digits = list(
all_categorical() ~ ifelse(.x == "{p}%", 1, 0),
all_continuous() ~ 0
),
missing_text = "(Missing)"
)
) %>%
# 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**"))