有没有办法将tbl_summary中的分类变量从显示为{p}%更改为比例


有没有办法将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
等级
I0.34
II0.34
III0.32

相关内容

  • 没有找到相关文章

最新更新