Skip to content

Instantly share code, notes, and snippets.

@elinw
Created May 30, 2017 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elinw/05644db3d42c731f598e1baf389f86e4 to your computer and use it in GitHub Desktop.
Save elinw/05644db3d42c731f598e1baf389f86e4 to your computer and use it in GitHub Desktop.
skim.data.frame <- function(.data) {
rows <- purrr::map(.data, skim_v)
combined <- dplyr::bind_rows(rows, .id = "var")
return(structure(combined, class = c("skim_df", class(combined))))
}
skim.grouped_df <- function(.data){
nested_df <- .data %>%
tidyr::nest()
groups <- as.character(dplyr::groups(.data))
group_values <- purrrlyr::by_row(nested_df[, groups], ~dplyr::combine(.))
skim_df <- nested_df %>%
dplyr::mutate(stats = purrr::map(data, skim)) %>%
dplyr::mutate(stats = purrr::map2(stats,
group_values$.out,
~append_group_vars(.x, .y, groups = groups)))
combined <- dplyr::bind_rows(skim_df$stats)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment