Skip to content

Instantly share code, notes, and snippets.

@larnsce
Last active September 3, 2020 09:21
Show Gist options
  • Save larnsce/6f7e84aac57d5b83e346a12e2ae36760 to your computer and use it in GitHub Desktop.
Save larnsce/6f7e84aac57d5b83e346a12e2ae36760 to your computer and use it in GitHub Desktop.
Use names in named list as columns of tibble
# sample data
tib <- tibble(
source = rep("ABC", 5),
year = seq(2016, 2020, 1)
)
# preprare list
tib_lst <- lst(
YEM = dat,
ZMB = dat,
ZWE = dat
)
# count number of rows and turn into dataframe with list element names as column
tib_lst %>%
# count rows of each list element
map(count) %>%
# turn list into tibble with list column
tibble::enframe() %>%
# turn list column into regular column
tidyr::unnest(cols = value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment