Skip to content

Instantly share code, notes, and snippets.

@EvaMaeRey
Created June 13, 2022 18:25
Show Gist options
  • Select an option

  • Save EvaMaeRey/8272ef8003e8a0fe378b0de6a54f9d45 to your computer and use it in GitHub Desktop.

Select an option

Save EvaMaeRey/8272ef8003e8a0fe378b0de6a54f9d45 to your computer and use it in GitHub Desktop.
flatten tabyl that is 3d
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()
@EvaMaeRey
Copy link
Author

also, unpivot?

@EvaMaeRey
Copy link
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