title: R - fastest way to select the rows of a matrix that satisfy multiple conditions
body: <p>This is an extension to the question on <a href="https://stackoverflow.com/questions/5391124/in-r-select-rows-of-a-matrix-that-meet-a-condition">returning the rows of a matrix that meet a condition</a> in R. Say I have the matrix:</p>
  
  <pre><code>       one two three four
   [1,]   1   6    11   16
   [2,]   2   7    12   17
   [3,]   3   8    11   18
   [4,]   4   9    11   19
   [5,]   5  10    15   20
   [6,]   1   6    15   20
   [7,]   5   7    12   20
  </code></pre>
  
  <p>I want to return all rows, where <code>matrix$two == 7</code> AND <code>matrix$three == 12</code> as fast as possible. This is the way I know to do it:</p>
  
  <pre><code> out &lt;- mat[mat$two == 7,]
   final_out &lt;- out[out$three == 12, ]
  </code></pre>
  
  <p>There should obviously be a method to get the contents of <code>final_out</code> in a one-liner, something like:  <code>final_out &lt;- which(mat$two == 7 &amp;&amp; mat$three == 12)</code> that is faster and more succinct than the two line of codes above. </p>
  
  <p>What is the fastest R code to return this multiple condition matrix query?</p>