Skip to content
Prev 157242 / 398506 Next

Generalising to n-dimensions

Laura Bonnett wrote:
Hi Laura.  I've been away (in Norwich).  Sorry not to give an example.

Variable 'a' is an array and variable 'd' is the same as in your 
original email.


 > a <- array(1:4,c(3,2,2,4))
 > d <- c(1,2)
 > f(a,d)
     [,1] [,2]
[1,]    1    4
[2,]    2    1
[3,]    3    2
 >


Thus in this case f(a,d) gives a[,,1,2].   Function f() is necessary because
you specified that the length of 'd' is not known in advance.

You can get 'd' from a single row of expand.grid() [but you will have to
coerce it to a matrix]

HTH

rksh