有没有办法将
tbl_summary
中的分类变量从显示为{p}%更改为比例?
举个例子,显示的不是48%,而是0.48。我尝试了style_percent和style number,但没有任何外观。我也尝试了datasummary
,但它不起作用,我无法在括号中显示平均值下的标准偏差。
tbl_summary(data = CPS, by = "Type",
include = c(Female, Hispanic,
age,
DadGradCollege,
MomGradCollege,
ftotval_def
),
statistic = list(all_continuous() ~ "{mean} n({sd})",
all_categorical() ~ "{p}%"),
label = list(
Female~ "Female",
Hispanic ~ "Hispanic",
age ~ "Age",
DadGradCollege ~ "Fathers with n t College",
MomGradCollege ~ "Mothers with n t College",
ftotval_def ~ "Total Family Income n t (1999 dollars)"
),
missing = "no")
是的,您可以使用digits=
参数来传递将对统计信息进行样式化/舍入/格式化的函数。下面的例子!
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.6.2'
trial |>
tbl_summary(
include = grade,
statistic = all_categorical() ~ "{p}",
digits = all_categorical() ~ function(x) style_number(x, digits = 2)
) %>%
as_kable() # convert to kable for SO
特征 | N=200 |
---|---|
等级 | |
I | 0.34 |
II | 0.34 |
III | 0.32 |