Last active
September 3, 2020 09:21
-
-
Save larnsce/6f7e84aac57d5b83e346a12e2ae36760 to your computer and use it in GitHub Desktop.
Use names in named list as columns of tibble
This file contains 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
# 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