GTsummary problems with percentages

Good evening,

I am currently using the package tbl_summary for summarising my data on R. In the statistic function I have put:

statistic = list(all_continuous() ~ "{mean} ({sd})",
all_categorical() ~ "{n} ({p}%)").

Nevertheless, The percentages that I get are all approximated.

Is there any way to put the exact percentage?

Thank you very much.

1 Like

Hello @juanpablosca,

Thanks for the question. We're still working out the best API for users to modify the function that styles the percentages. In the meantime, you can use a gtsummary theme to change the function. See example below. There are more details about themes here: gtsummary themes • gtsummary


# set function for rounding percentages
list("tbl_summary-fn:percent_fun" = function(x) sprintf(x * 100, fmt='%#.2f')) %>%

trial %>%
  select(grade, response) %>%

Thank you for your help.

But I still have a problem

When I have tried to run your code the system told me that the function set_gtsummary_theme() does not exist.

Do you know how can I solve this problem?

Hi @juanpablosca, You'll just need to update the package (the function is a somewhat newer arrival).

Thank you for your help!!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.