Indexing a matrix with another matrix in R - index out of bounds
<p>I am experiencing some strange behavior in R when trying to index a matrix with another matrix. I run into an error of subscript out of bounds with indexing with a 2 column matrix, but not with a four column matrix. See the following reproducible code. Any insight would be appreciated!</p>

<p>This</p>

<pre><code>data &lt;- matrix(rbinom(100, 1, .5), nrow = 10)
idx &lt;- cbind(1:50, 51:100)
data[idx]
</code></pre>

<p>results in:</p>

<pre><code>Error in data[idx] : subscript out of bounds
</code></pre>

<p>However </p>

<pre><code>data[cbind(idx,idx)]
</code></pre>

<p>works.</p>

<p>My session info:</p>

<pre><code>R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin15.5.0 (64-bit)
Running under: OS X 10.11.5 (El Capitan)
</code></pre>