我试图使用sjPlot
来生成描述性统计表,并且试图设置小数点后的位数。
这是我尝试过的方法(下面的可复制示例):
library(sjPlot)
library(sjmisc)
tab_df(mtcars, digits = 1)
descr(mtcars) %>%
tab_df(digits = 1)
在两种情况下,小数点后仍然有很多数字。
下面丹尼尔(Daniel)的代码产生的结果与我想要的结果很接近,但是您仍然可以看到尾随的零被四舍五入了,因此并不是所有的数字都精确到两位小数。
library(sjPlot)
library(sjmisc)
tab_df(mtcars, digits = 1)
descr(mtcars) %>%
tab_df(digits = 1)
答案 0 :(得分:1)
一种快速的解决方法是使用sjmisc::round_num()
:
library(sjPlot)
library(sjmisc)
tab_df(mtcars, digits = 1)
descr(mtcars) %>%
round_num(2) %>%
tab_df()