[R] Problem indexing into array

Ted Harding Ted.Harding at nessie.mcc.ac.uk
Fri Jul 18 22:13:33 CEST 2003


> mu[M[,1:3]]
> 
> should do what you want, I think.  See chapter 1 of S Poetry.
> 
> Patrick Burns

Thanks Patrick (and honoured to hear from the author of S-Poetry!).

This doesn't do what I want (I was probably not clear), though
Tony Plate's reply looks promising if maybe cumbersome.
(Thanks, Tony).

Basically: Given that mu was made by

  mu<-array(data=x, dim=c(9,2,2,2))

say, where x has 72 reals in it, and given that the first three columns
of M contain values (1 or 2) of p,q,r, I want to recover from mu
the 9 values mu[,p,q,r] where (p,q,r) is the result of M[i,1:3] for
some value of i.

I don't want to do this as mu[,M[,1],M[,2],M[,3]] because in fact
this is taking place inside a function where the dimensions of the
arrays thrown at the function will not be known beforehand.

And, if the result can be got for all rows of M in one swoop, instead
of looping through the rows of M, all the better!

Thanks!
Ted.




More information about the R-help mailing list