Hello everyone, I am working on summarising surveillance data by district as part of a reporting workflow. I want to:
-
Count cases by district
-
Sort in descending order
-
Add a totals row
-
Format percentages
-
Convert the table to a
qflextable()for reporting
Here is the code I am using:
library(janitor)
library(dplyr)
library(qflextable)
surv %>%
tabyl(district, show_na = FALSE) %>%
arrange(-n) %>%
adorn_totals() %>%
adorn_pct_formatting(digits = 2) %>%
qflextable()
When I apply both sorting and formatting before converting to qflextable, I sometimes get:
-
A warning or error message
-
Percent formatting not applying to the totals row
What I have tried:
-
Checked the Epi R Handbook section on
tabyl() -
Reviewed StackOverflow threads about
adorn_*()function ordering -
Attempted changing the order of
adorn_totals()andadorn_pct_formatting()
Still unsure what the recommended order should be so everything displays correctly.
