title: How to extract all sublists from a list in r?
body: <p>There were many close solutions but unfortunately I could not figure out the right one. I have a list of lists like below. As you can see there are 3 sublists (01-2011,02-2011 and 01-2012) under their up list. But I want to get only lists with names <code>(01-2011,02-2011 and 01-2012)</code> </p>
  
  <p>Here is my data and its structure;</p>
  
  <pre><code>data&lt;-list(structure(list(`01-2011` = structure(list(dmax = structure(list(
      m5 = 0.266, m10 = 0.532, m15 = 0.797, m30 = 1.092), .Names = c("m5", 
  "m10", "m15", "m30"))), .Names = "dmax"), `01-2012` = structure(list(
      dmax = structure(list(m5 = 1.224, m10 = 2.395, m15 = 3.063, 
          m30 = 5.131), .Names = c("m5", "m10", "m15", "m30"))), .Names = "dmax")), .Names = c("01-2011", 
  "01-2012")), structure(list(`02-2011` = structure(list(dmax = structure(list(
      m5 = 0.955, m10 = 1.683, m15 = 2.398, m30 = 4.539), .Names = c("m5", 
  "m10", "m15", "m30"))), .Names = "dmax")), .Names = "02-2011"))
  
  
  [[1]]
  [[1]]$`01-2011`
  [[1]]$`01-2011`$dmax
  [[1]]$`01-2011`$dmax$m5
  [1] 0.266
  
  [[1]]$`01-2011`$dmax$m10
  [1] 0.532
  
  [[1]]$`01-2011`$dmax$m15
  [1] 0.797
  
  [[1]]$`01-2011`$dmax$m30
  [1] 1.092
  
  
  
  [[1]]$`01-2012`
  [[1]]$`01-2012`$dmax
  [[1]]$`01-2012`$dmax$m5
  [1] 1.224
  
  [[1]]$`01-2012`$dmax$m10
  [1] 2.395
  
  [[1]]$`01-2012`$dmax$m15
  [1] 3.063
  
  [[1]]$`01-2012`$dmax$m30
  [1] 5.131
  
  
  
  
  [[2]]
  [[2]]$`02-2011`
  [[2]]$`02-2011`$dmax
  [[2]]$`02-2011`$dmax$m5
  [1] 0.955
  
  [[2]]$`02-2011`$dmax$m10
  [1] 1.683
  
  [[2]]$`02-2011`$dmax$m15
  [1] 2.398
  
  [[2]]$`02-2011`$dmax$m30
  [1] 4.539
  </code></pre>
  
  <p>I tried <code>lapply(data, "[[")</code> but this gave an error. </p>
  
  <p>Here is desired output;</p>
  
  <pre><code>out&lt;-structure(list(`01-2011` = structure(list(dmax = structure(list(
      m5 = 0.266, m10 = 0.532, m15 = 0.797, m30 = 1.092), .Names = c("m5", 
  "m10", "m15", "m30"))), .Names = "dmax"), `01-2012` = structure(list(
      dmax = structure(list(m5 = 1.224, m10 = 2.395, m15 = 3.063, 
          m30 = 5.131), .Names = c("m5", "m10", "m15", "m30"))), .Names = "dmax"), 
      `02-2011` = structure(list(dmax = structure(list(m5 = 0.955, 
          m10 = 1.683, m15 = 2.398, m30 = 4.539), .Names = c("m5", 
      "m10", "m15", "m30"))), .Names = "dmax")), .Names = c("01-2011", 
  "01-2012", "02-2011"))
  
  
  
  $`01-2011`
  $`01-2011`$dmax
  $`01-2011`$dmax$m5
  [1] 0.266
  
  $`01-2011`$dmax$m10
  [1] 0.532
  
  $`01-2011`$dmax$m15
  [1] 0.797
  
  $`01-2011`$dmax$m30
  [1] 1.092
  
  
  
  $`01-2012`
  $`01-2012`$dmax
  $`01-2012`$dmax$m5
  [1] 1.224
  
  $`01-2012`$dmax$m10
  [1] 2.395
  
  $`01-2012`$dmax$m15
  [1] 3.063
  
  $`01-2012`$dmax$m30
  [1] 5.131
  
  
  
  $`02-2011`
  $`02-2011`$dmax
  $`02-2011`$dmax$m5
  [1] 0.955
  
  $`02-2011`$dmax$m10
  [1] 1.683
  
  $`02-2011`$dmax$m15
  [1] 2.398
  
  $`02-2011`$dmax$m30
  [1] 4.539
  </code></pre>