Closed cole-johanson closed 3 years ago
I think you did not understand the purpose of digits.pct
(maybe the documentation wasn't very clear). In table1
, rounding is handled different for "ordinary" numeric values like means, and for percentages (i.e. for categorical variables, or %missing values), by default (obviously everything is customizable, but this is the default behavior). The digits.pct
option applies specifically to the latter (i.e. percentages), while the digits
option applies in the more general case. I modified you example by adding a categorical variable to demonstrate:
library(table1)
df = data.frame(x=c(1,2,2), y=c("A", "A", "B"))
table1(~ x + y , data=df, digits.pct=5)
As you can see, the percentages have 5 decimal places, while other numeric values have 3 significant digits.
Thank you. Re-reading without looking for functionality that does not exist, I see the documentation is actually quite clear:
An integer specifying the number of digits after the decimal place for percentages.
I will open a separate feature request.
You can see the mean 1.67 does not change to 1.667 when digits.pct=3. I suggest updating the stats.apply.rounding function to accept
digits = NULL
, which will trigger the use of digits.pct instead. Something like: