r - tbl_summary : How to set t. 测试列保留 2 位小数 (gtsummary)

标签 r summary gtsummary

我对 tbl_summary 还很陌生,正在尝试将 t.test 列设置为小数点后两位。

我在 tbl_summary() 行中尝试了几种不同的方法,但它似乎没有改变 t.test 列。尝试添加 style_fun = everything() ~ purrr::partial(style_number,digits = 2) 但这导致出现以下错误消息: ... 必须是空的。 ✖ 有问题的参数: • style_fun = everything() ~ purrr::partial(style_number,digits = 2)。关于如何改变它有什么想法吗?

此外,是否可以更改 CI 列,使其读取为conf.low - conf.high,而不是conf.low、conf.high。 谢谢!

我在这里使用了 mtcars 示例以使其更容易。

car <- mtcars[,c("am", "mpg", "qsec", "disp")]

car %>%
  dplyr::select(am, mpg, qsec, disp) %>%
  tbl_summary(
    by="am",
    statistic = list(all_continuous() ~ "{mean} (±{sd})"),
    digits = all_continuous() ~ 2
  ) %>%
  add_p(test = all_continuous() ~ "t.test") %>%
  modify_header(statistic ~ "**Test Statistic**") %>%
  modify_fmt_fun(statistic ~ style_number) %>%
  add_ci()

最佳答案

您关于使用 modify_fmt_fun 的说法是正确的,但 style_number 需要包装在函数中。

library(gtsummary)

car <- mtcars[,c("am", "mpg", "qsec", "disp")]

car %>%
  dplyr::select(am, mpg, qsec, disp) %>%
  tbl_summary(
    by="am",
    statistic = list(all_continuous() ~ "{mean} (±{sd})"),
    digits = all_continuous() ~ 2
  ) %>%
  add_p(test = all_continuous() ~ "t.test") %>%
  modify_header(statistic ~ "**Test Statistic**") %>%
  modify_fmt_fun(update = statistic ~ function(x) style_number(x, digits = 2)) %>%
  add_ci() 

enter image description here

关于r - tbl_summary : How to set t. 测试列保留 2 位小数 (gtsummary),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75194980/

相关文章:

css - 在 R 数据表中添加单元格边框

java - RCaller 抛出 java.io.IOException/ExecutionException

R使用将成为不同分母的单元格在数据框中创建汇总百分比

r - gtsummary 中的 Wald 置信区间

r - 根据向量中的命名属性拆分向量列表

jquery - 如何在 R Shiny 中右对齐 DataTable 的列?

php - 如何在 MYSQL 中获取汇总计数

r - Data Frame,错误总结

r - 为 R 中 tbl_summary 函数的 gtsummary 包中的分类变量和连续变量设置主题

gtsummary - 更改 gtsummary 摘要表中 "add_p()"函数执行的默认统计测试