[英]How to format the number of digits for categorical variables in 'gtsummary::tbl_summary'?
我無法弄清楚在匯總分類變量時如何告訴 tbl_summary 函數顯示小數位。 它適用於像“mpg”這樣的連續變量,但不適用於“cyl”。
library(tidyverse)
library(gtsummary)
# with decimal places
mtcars %>%
select(mpg) %>%
tbl_summary(digits = list(everything() ~ c(2)))
# no decimal places
mtcars %>%
select(cyl) %>%
tbl_summary(digits = list(everything() ~ c(2)))
謝謝!
里奇
要更新位數,百分比四舍五入以使用digits=
參數。 在下面的示例中,傳遞c(0, 2)
。 零表示將 N 舍入到最接近的整數,而 2 表示將百分比舍入到 2 位小數。
快樂編碼!
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.4.0'
# with decimal places
tbl <-
mtcars %>%
select(cyl) %>%
tbl_summary(digits = list(all_categorical() ~ c(0, 2)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.