I'm trying to use sjPlot
to produce a table of Descriptive Statistics, and I am trying to set the number of digits after the decimal point.
This is what I've tried (reproducible example below):
library(sjPlot)
library(sjmisc)
tab_df(mtcars, digits = 1)
descr(mtcars) %>%
tab_df(digits = 1)
In both cases, I'm still getting many digits trailing after the decimal point.
The code below from Daniel produces close to the result I'm looking for, but you can still see that trailing zeros are being rounded off, so not all numbers are to two decimal places.
library(sjPlot)
library(sjmisc)
tab_df(mtcars, digits = 1)
descr(mtcars) %>%
tab_df(digits = 1)
A quick workaround would be using sjmisc::round_num()
:
library(sjPlot)
library(sjmisc)
tab_df(mtcars, digits = 1)
descr(mtcars) %>%
round_num(2) %>%
tab_df()