phill phill - 2 months ago 9
R Question

Split a group of lists R

I've got a group of 12 lists that forms a vector represented by data of one specific year (each month is represented by one list).

I would like to know how to split this group of lists in 12 lists, one for each month of the year.


Suppose you have a list of lists, and each element is named:

ll <- list(jan = list(1:3),
           feb = list(4:6),
           mar = list(7:9))
# [1] "ll"

You can use list2env to assign the list components into the global environment:

list2env(ll, globalenv())
# [1] "feb" "jan" "ll"  "mar"

# [[1]]
# [1] 1 2 3