title: In R, how to filter lists of lists?
body: <p>According to the manual, <a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/funprog.html" rel="noreferrer">Filter</a> works on vectors, and it happens to work also on lists, eg.:</p>
  
  <pre><code>z &lt;- list(a=1, b=2, c=3)
  Filter(function(i){
    z[[i]] &gt; 1
  }, z)
  $b
  [1] 2
  
  $c
  [1] 3
  </code></pre>
  
  <p>However, it doesn't work on lists of lists, eg.:</p>
  
  <pre><code>z &lt;- list(z1=list(a=1,b=2,c=3), z2=list(a=1,b=1,c=1), z3=list())
  Filter(function(i){
    if(length(z[[i]])&gt;0){
      if(z[[i]]$b &gt; 1)
        TRUE
      else
        FALSE
    }
    else
      FALSE
  }, z)
  Error in z[[i]] : invalid subscript type 'list'
  </code></pre>
  
  <p>What is the best way then to filter lists of lists without using nested loops? It could also be lists of lists of lists...</p>
  
  <p>(I tried with nested lapply's instead, but couldn't manage to make it work.)</p>
  
  <p><strong>Edit:</strong> in the 2nd example, here is what I want to obtain:</p>
  
  <pre><code>list(z1=list(a=1,b=2,c=3))
  </code></pre>
  
  <p>that is, without z$z2 because z$z2$b &lt; 1, and without z$z3 because it is empty.</p>