title: Matrix Indexing R
body: <p>I'm trying to index a matrix in R using this code:</p>
  
  <pre><code>test &lt;- matrix(0, nrow = 10, ncol = 2) 
  test[1:10, 1]  &lt;- 1:10
  test[1:10, 2]  &lt;- 11:20
  
  index &lt;- c(1,2,1,1,2,1,1,2,1,2)
  
  answer &lt;- test[ , index]
  </code></pre>
  
  <p>I receive a 10 x 10 matrix.  But I would like to receive a vector.  </p>
  
  <p><code>[1]  1 12  3  4 15  6  7 18  9 20</code></p>
  
  <p>Any ideas?</p>
  
  <p>Edit:
  Also, how one could use exclusionary indexing (e.g., <code>-index</code>) to exclude values from the matrix.</p>
  
  <p><code>[1]  11 2  13  14 5  16  17 8  19 10</code></p>