phill phill - 1 year ago 99
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download