I have a simple question of indexing an array for multidimensional arrays in R. I do a lot of simulations, each of which gives a result in the form of a matrix where entries are classified by category. So, for example, the result looks like
aresult<-array(sample(1:3, 6, replace=T), dim=c(2,5), dimnames=list( c("prey1", "prey2"), c("predator1", "predator2", "predator3", "predator4", "predator5")))
Now I want to save the results of my experiments in a 3D matrix, where the first two dimensions are the same as in aresult , and in the third dimension the number of experiments that fall into each category. So my count arrays should look like
Counts<-array(0, dim=c(2, 5, 3), dimnames=list( c("prey1", "prey2"), c("predator1", "predator2", "predator3", "predator4", "predator5"), c("n1", "n2", "n3")))
and after each experiment, I want to increase the numbers in the third dimension by 1, using the values ββin aresults as indices.
How can I do this without using loops?