I have the following hypothetical list
test <- list(a = c("United", "States", "of", "America", "2021", "North", "America"),
b = c("Canada", "2021", "North", "America"),
c = c("Morocco", "2021", "Africa"),
d = c("South", "Africa", "2021", "Africa"),
e = c("Faroe", "Islands", "2021", "Europe"),
f = c("Spain", "2021", "Europe"))
I would like produce the following tibble:
| country | year | continent |
|---|---|---|
| United States of America | 2021 | North America |
| Canada | 2021 | North America |
| Morocco | 2021 | Africa |
| South Africa | 2021 | Africa |
| Faroe Islands | 2021 | Europe |
| Spain | 2021 | Europe |
I tried to use the ldply() function of the plyr package. However, my list elements have unequal lengths, because of compound names.
How could I join this data in a tibble with the variables: country, year and continent, for example?