title: How to subset a list based on its elements - R
body: <p>I would like to select a subset of a list based on the value of the elements.
  I thought this would be simple, and I think I'm close-ish. But I need some help.</p>
  
  <p>I have a list of 'features' ChemFeats.all:</p>
  
  <pre><code>&gt; str(ChemFeats.all)
  List of 20
   $ HPh_feats       : chr [1:4] "f_225" "f_3006" "f_2876" "f_2480"
   $ PhCN_feats      : chr "f_3285"
   $ PhCA_feats      : chr [1:2] "f_2477" "f_189"
   $ PYO_feats       : chr "f_3284"
   $ HHQ_feats       : chr [1:5] "f_3001" "f_750" "f_589" "f_186" ...
   $ PQS_feats       : chr [1:4] "f_2334" "f_2" "f_185" "f_408"
  </code></pre>
  
  <p>And I have a vector of "good" features:</p>
  
  <pre><code>&gt; str(gd_feats)
   chr [1:43] "f_649" "f_70" "f_711" "f_748" "f_3" "f_414" "f_2181" ...
  </code></pre>
  
  <p>Now I want a subset of the first list only containing the good features.
  Here is one of my attempts, I have tried a few similar versions, some being closer than others.</p>
  
  <pre><code>ChemFeats.all.GdFts&lt;-lapply(ChemFeats.all, '[',function(x) match(x, gd_feats))
  </code></pre>
  
  <p>Thanks for any help,</p>