Hello RStudio community,
I need help with with formating tables using janitor package in R if somebody can help me. It is appreciated. Thanks
# In the first table, how to get the table by having values first and then percent in the bracket format (value (%))?
library(dplyr)
humans <- starwars %>%
filter(species == "Human")
# table1
library(janitor)
humans %>%
tabyl(eye_color, skin_color, gender, show_missing_levels = FALSE) %>%
adorn_totals(c("row", "col")) %>%
adorn_percentages("row") %>%
adorn_pct_formatting(digits = 1) %>%
adorn_ns %>%
adorn_title
#table2
# table 2 is similar to table 1 with using knitr::kable(). How to get subtiles for sub-group table (feminine) and sub-group table (masculine) ?
humans %>%
tabyl(eye_color, skin_color, gender, show_missing_levels = FALSE) %>%
adorn_totals(c("row", "col")) %>%
adorn_percentages("row") %>%
adorn_pct_formatting(rounding = "half up", digits = 0) %>%
adorn_ns() %>%
adorn_title("combined") %>%
knitr::kable()
You might want to have a look at flextable. It seems rather versatile. Or another package from the same author, gtsummary, might work. Disclaimer, I have never used gtsummary.
As nirgrahamuk says it does not look like janitor will do what you need.