Specifying significant numbers for percent
I am looking for a way to express counts and percentage with k significant numbers, i.e. overcoming the current default of setting the number of decimal for the percents. In my exemple, I would like 91% and 9.1%, but with combination of parameters digits and digits.pct, I can only have one of the two. Thanks
x <- c(rep("A", 10), "B")
table1( ~ x, digits.pct = 1)
Okay, I admit this isn't great, but the following works:
table1( ~ x, render.categorical = function(x, ...) {
c("", sapply(stats.default(x), function(y) with(y, sprintf("%s (%0.2g%%)", FREQ, PCT))))
})
I need to think about a better way to integrate the functionality.
Great. Thanks Benjamin.
I get that the point is to avoid using stats.apply.rounding() in the definition of render.categorical. I adapted your solution for my needs with signif_pad().