I would like to use janitor::tabyl to create two-way tabulations for every variable with respect a given variable in the data. For example
library(tidyverse)
library(janitor)
humans <- starwars %>%
filter(species == "Human")
t2 <- humans %>%
tabyl(gender, eye_color)
t2 %>%
adorn_percentages("row") %>%
adorn_pct_formatting(digits = 2) %>%
adorn_ns()
#> gender blue blue-gray brown dark hazel yellow
#> female 33.33% (3) 0.00% (0) 55.56% (5) 0.00% (0) 11.11% (1) 0.00% (0)
#> male 34.62% (9) 3.85% (1) 46.15% (12) 3.85% (1) 3.85% (1) 7.69% (2)
I would ideally like to use purrr:map to iterate through every other variable and do the above tabulation with respect to gender. So far I have created the main tabulation following this post
humans %>%
select_if(is.character) %>%
select(-name, -gender) %>%
imap(.f = ~janitor::tabyl(dat = humans, !!sym(.y), gender))
But I am having trouble applying a similar logic to the adorn_* calls previously provided
Is there a way that this can be done using purrr?
I don't think anything changes in
imapcall as well, you can just pipe (%>%) the functions similarly :