Skip to content
Prev 267251 / 398502 Next

General indexing in multidimensional arrays

On Aug 1, 2011, at 10:50 AM, Duncan Murdoch wrote:

            
Is this the right answer?

 > result<- which(indices, arr.ind=TRUE)
 > result
      row col
[1,]   4   1
[2,]   1   3

 > apply(result, 1, function(x) data[x[1], x[2], ])
             [,1]       [,2]
[1,]  1.62880528  0.7781005
[2,] -0.08861725 -2.1791674
[3,]  0.78242531 -1.0352826
[4,]  1.40012118 -1.2541230

....if so, it should be possible to encapsulate that behavior in a  
function.