title: Index a matrix using two equal-length vectors for row and column indices
body: <p>Imagine you have a 5x5 matrix and want to select values using two equal-length vectors, one representing the index row and the other representing the index column:</p>
  
  <pre><code>m &lt;- matrix(1:25, ncol = 5)
  R &lt;- c(1, 3, 5)
  C &lt;- c(2, 4, 4)
  </code></pre>
  
  <p>The desired output here is a single vector of of <code>6</code> (row 1, column 2), <code>18</code> (row 3, column 4), <code>20</code> (row 5, column 4).</p>
  
  <p>The best I could come up with was:</p>
  
  <pre><code>diag(m[R,C])
  </code></pre>
  
  <p>But this constructs a matrix of size <code>length(R) * length(C)</code> and so is slow if R and C are long.</p>
  
  <p>How do you do this?</p>