title: subset a list within a list by column's name start with all requested pattern
body: <p>I have a list of data frames (L) with different column's name. I want to have a subset of a list which contains all requested columns name start with A and B (the sequence of A and B is not important.</p>
  <pre><code>L1 = data.frame(A1 = c(1:4) , Ab = c(&quot;u&quot;,&quot;v&quot;,&quot;w&quot;,&quot;x&quot;))
  L2 = data.frame(A2 = c(1:4) , Bc = c(&quot;u&quot;,&quot;v&quot;,&quot;w&quot;,&quot;x&quot;))
  L3 = data.frame(A3 = c(1:4) , Bd = c(&quot;u&quot;,&quot;v&quot;,&quot;w&quot;,&quot;x&quot;))
  L4 = data.frame(A = c(1:4) , B = c(&quot;u&quot;,&quot;v&quot;,&quot;w&quot;,&quot;x&quot;))
  L&lt;-list(L1,L2, L3, L4)
  </code></pre>
  <p>The result should be a list with L2, L3, and L4 which contains columns start with A and B.</p>
  <p>#######
  Following command gives all lists which contain columns start with A or B but not subset a list which just start with both A and B.</p>
  <pre><code>lapply(L, function(x)   x[ , grepl( '^A|^B' , names(x))])
  </code></pre>
  <p>#######
  and this function gives lists with exact requested columns name and not the columns start with A and B.</p>
  <pre><code>trial &lt;- function(x) 
  {
    reqnames &lt;- c('A', 'B')
    L &lt;- lapply(L, function(x)   all(reqnames  %in% names(x)))
    L &lt;- which(L==1)
    x[L]
  }
   trial(L)
  </code></pre>