Skip to content

Instantly share code, notes, and snippets.

@jkaupp
Last active April 13, 2018 00:54
Show Gist options
  • Save jkaupp/96ee6f153156d5322483118e995ee077 to your computer and use it in GitHub Desktop.
Save jkaupp/96ee6f153156d5322483118e995ee077 to your computer and use it in GitHub Desktop.
Reading in multiple tables in excel file, groups delimited by #
library(tidyverse)
library(rlang)
merge_tbls <- function(x) {
col <- sym(names(x)[1])
idx <- filter(x, grepl("#", !!col)) %>%
pull(!!col) %>%
parse_number()
filter(x, !grepl("#", !!col)) %>%
mutate(group = idx)
}
split(df, cumsum(seq_along(df$col1) %in% which(grepl("#", df$col1))[-1])) %>%
map_dfr(merge_tbls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment