You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让tidycmprsk包的tbl_cuminc函数显示>10值的小数位?

解决tidycmprsk中tbl_cuminc百分比统一显示一位小数的问题

要让tbl_cuminc()生成的所有百分比(包括大于10的数值)都显示一位小数,只需通过estimate_fun和ci_fun参数自定义格式化函数,统一设置显示格式:

library(tidycmprsk)

# 自定义格式化函数:将数值转为保留1位小数的百分比
format_one_decimal_pct <- function(x) {
  sprintf("%.1f%%", x * 100)
}

cuminc(Surv(ttdeath, death_cr) ~ trt, trial) |> 
  tbl_cuminc(
    times = c(12, 24), 
    label_header = "**Month {time}**",
    estimate_fun = format_one_decimal_pct,  # 控制发生率的显示格式
    ci_fun = format_one_decimal_pct         # 控制置信区间的显示格式
  ) |> 
  gtsummary::as_kable()

输出效果

执行上述代码后,表格中的所有百分比都会统一显示一位小数:

CharacteristicMonth 12Month 24
Chemotherapy Treatment
Drug A3.1% (0.8%, 8.0%)24.0% (16.0%, 33.0%)
Drug B8.8% (4.3%, 15.0%)32.0% (23.0%, 42.0%)

内容的提问来源于stack exchange,提问作者user27442451

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 00:04:57