Skip to content
Prev 108571 / 398500 Next

Index mapping on arrays

Hello Demi


The trick for array indexing
on an array A, where length(dim(A))==n,
is to use an n-column matrix M to extract the elements
by rows of M.

If I understand correctly, the following should help:


 > A <- array(1:18,c(3,3,2))
 > x <- 2:3
 > y <- 1:2
 > A[cbind(x,y,1)]
[1] 2 6




You may find the following useful too:

 > A[as.matrix(cbind(1,expand.grid(x,y)))]
[1]  4  7 13 16
 >


best

rksh
On 1 Feb 2007, at 13:34, Demi Anderson wrote:

            
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743