Created
June 13, 2022 18:25
-
-
Save EvaMaeRey/8272ef8003e8a0fe378b0de6a54f9d45 to your computer and use it in GitHub Desktop.
flatten tabyl that is 3d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tabyl_flatten <- function(tabyl3d){ | |
| my_tibble <- tibble() | |
| for (i in 1:length(tabyl3d)){ | |
| meta_name <- names(tabyl3d)[i] | |
| my_tibble %>% | |
| bind_rows(tabyl3d[[i]] %>% | |
| mutate(category = meta_name, .before = 1)) -> | |
| my_tibble | |
| } | |
| my_tibble | |
| } | |
| tidytitanic::tidy_titanic %>% | |
| janitor::tabyl(sex, class, age) %>% | |
| tabyl_flatten() |
Author
Author
tidytitanic::tidy_titanic %>%
janitor::tabyl(sex, class, age) %>%
janitor::adorn_totals(where = c("row","col")) %>%
janitor::adorn_percentages(denominator = "col") %>%
janitor::adorn_pct_formatting(digits = 0) %>%
janitor::adorn_ns(position = "front") %>%
tabyl_flatten() %>%
group_by(category) %>%
gt::gt()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
also, unpivot?