title: Analog of subset for lists
body: <p>I'd like to subset a list of sublists, based on the contents of one of the sublist elements, in a manner similar to the way <code>subset</code> works on data frames:</p>
  
  <pre><code>sublist1 &lt;- list(data=rnorm(10), name="name1", keepMe=2)
  sublist2 &lt;- list(data=rnorm(10), name="name2", keepMe=2)
  sublist3 &lt;- list(data=rnorm(10), name="name3", keepMe=3)
  myList &lt;- list(s1=sublist1, s2=sublist2, s3=sublist3)
  </code></pre>
  
  <p>I'd like to do something like <code>keepers &lt;- subset[myList, keepMe==2]</code> which would return a list of length 2.</p>
  
  <p>The following is <em>almost</em> what I want:</p>
  
  <pre><code>require(plyr)
  selector &lt;- function(x) {
    if (x$keepMe==2) {return(x)} 
    else {return(NULL)}
  }
  keepers &lt;- llply(myList, selector)
  </code></pre>
  
  <p>except that in that case the undesirable list elements don't get thrown out, they just get replaced with <code>NULL</code>.</p>
  
  <p>Note that in all cases the sublists will have the same components, only the values of the components change. </p>