title: R array indexing for multi-dimensional arrays
body: <p>I have a simple array indexing question for multi-dimensional arrays in R. I am doing a lot of simulations that each give a result as a matrix, where the entries are classified into categories. So for example a result looks like</p>
  
  <pre><code>aresult&lt;-array(sample(1:3, 6, replace=T), dim=c(2,5), 
                 dimnames=list(
                   c("prey1", "prey2"), 
                   c("predator1", "predator2", "predator3", "predator4", "predator5")))
  </code></pre>
  
  <p>Now I want to store the results of my experiments in a 3D-matrix, where the first two dimension are the same as in <code>aresult</code> and the third dimension holds the number of experiments that fell into each category. So my arrays of counts should look like</p>
  
  <pre><code>Counts&lt;-array(0, dim=c(2, 5, 3), 
                dimnames=list(
                  c("prey1", "prey2"), 
                  c("predator1", "predator2", "predator3", "predator4", "predator5"),
                  c("n1", "n2", "n3")))
  </code></pre>
  
  <p>and after each experiment I want to increment the numbers in the third dimension by 1, using the values in <code>aresults</code> as indexes.</p>
  
  <p>How can I do that without using loops?</p>