[R] indexing an array
Agustin Lobo
alobo at ija.csic.es
Thu Sep 20 14:05:37 CEST 2001
Is not
lambda[rep(1:N,rep(3,N),state[rep(1:N,rep(3,N)],] ?
(i.e., for N=5 , the first index is:
> rep(1:5,rep(3,5))
[1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5
but make sure that state[rep(1:N,rep(3,N)] is within 1:M.
Agus
Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es
On Thu, 20 Sep 2001 siim at obs.ee wrote:
> 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
>
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list