title: Subset variables matching pairs of values in R
body: <p>From a given data frame (<code>myData</code>, in the example below), I would like to subset the variables with values matching at least one pair of values stored in a list (<code>myList</code>, in the example below).</p>
  <pre><code>myList &lt;- list(c(8,15), c(2,3))
  
  v1 &lt;- c(1, 2, 3, 8, 15)
  v2 &lt;- c(3, 7, 8, 9, 10)
  v3 &lt;- c(2, 4, 5, 6, 7)
  v4 &lt;- c(8, 15, 6, 7, 9)
  
  myData &lt;- cbind(v1, v2, v3, v4) 
  </code></pre>
  <p>Ideally the subset should consists only of <code>v1</code> and <code>v4</code> because in v1 occurs the pair 8,15 and the pair 2,3, and in v4 occur the pair 8,15.</p>
  <p>I tried to use the <code>which</code> statement for a single pair (i.e., 8, 15), as follows:</p>
  <pre><code>subset &lt;- myData[which(myData==unlist(myList[[1]][1]) &amp; myData==unlist(myList[[1]][2]))]
  </code></pre>
  <p>Still, the output is an empty integer. Am I missing something in the <code>which</code> statement? Plus, how could I implement the code for more than one pair of values?</p>