-5

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.

SashaZd
  • 3,315
  • 1
  • 26
  • 48
phill
  • 95
  • 2
  • 10
  • You're not supposed to ask for code solutions directly on StackOverflow. If you can add what you tried so far, the community should be able to help you figure out what the error in your code/logic is. – SashaZd Aug 21 '16 at 22:07
  • I don't know what you mean by *"a group of lists that forms a vector"* Do you mean a list of lists? A list of vectors? Just a vector? `group` isn't a data structure in R. When you say that the result you want is 12 lists, do you really mean 12 objects of class `list` or do you want 12 vectors? Please [see these tips on making a reproducible example](http://stackoverflow.com/q/5963269/903061) and then clarify both your current data structure and your desired output. Also have a look at `?split` and see if that meets your needs. – Gregor Thomas Aug 21 '16 at 22:12
  • Gregor, thanks for attention. Actually, what I meant to say is a list of 12 lists. The result i`m looking for is 12 objects of class list. – phill Aug 21 '16 at 22:50
  • On StackOverflow, you need to provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), especially with questions like this. Also see [minimum, complete, verifiable examples](http://stackoverflow.com/help/mcve). Bottom line: don't make us guess at *sample* data, structure, and brief code you've already tried. – r2evans Aug 21 '16 at 23:23
  • On top of all that, there are literally hundreds of returns if you search in SO for ["\[r\] split list"](http://stackoverflow.com/search?q=%5Br%5D+split+list), I suggest you look for similar questions first, it's often already been asked (and answered). – r2evans Aug 21 '16 at 23:25

1 Answers1

-1

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))
ls()
# [1] "ll"

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

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

jan
# [[1]]
# [1] 1 2 3
Weihuang Wong
  • 12,868
  • 2
  • 27
  • 48
  • It worked! Thank you very much. – phill Aug 22 '16 at 00:26
  • 3
    @phill - This is really not recommended. Before you had a list which presumably had a nice order, January as `listname[1]`, February as `listname[2]` etc, and an easy way to make changes to the whole year via `lapply(listname, functionname)` . Now you have a bunch of unrelated objects in the global environment that are unordered and can't be bundled for consistent handling. – thelatemail Aug 22 '16 at 00:37