Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying significant numbers for percent #100

Open
slevu opened this issue Mar 7, 2023 · 2 comments
Open

Specifying significant numbers for percent #100

slevu opened this issue Mar 7, 2023 · 2 comments

Comments

@slevu
Copy link

slevu commented Mar 7, 2023

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)

@slevu slevu changed the title specifying significant numbers for percent Specifying significant numbers for percent Mar 7, 2023
@benjaminrich
Copy link
Owner

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.

@slevu
Copy link
Author

slevu commented Mar 9, 2023

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants