[R] indexing an array

siim@obs.ee
Thu, 20 Sep 2001 07:57:15 -0000

Dear everybody,

I have a following problem.  I have a 3D array

lambda <- array( dim=c(N,M,M-1))

where I have to extract the elements as follows:

lambda[ 1, state[1], 1]
lambda[ 1, state[1], 2]
...
lambda[ 1, state[1], M-1]
lambda[ 2, state[2], 1]
...
lambda[ 2, state[2], M-1]
...
lambda[ N, state[N], M-1]

i.e. the result should be a 2D array, where the second index follows the
first one and the third is free (lambda[i,state[i],]).  The process is
to be repeated so I do not want to write a cycle.

Any suggestions?

Thanks in advance,

Ott Toomet