[R] coerce vector into array - change filling sequence

Kohleth Chia kohleth at gmail.com
Tue Jan 12 13:05:32 CET 2010


Dear all,

When I coerce a vector into a multi dimensional array, I would like R to start filling the array along the last dimension, then the 2nd last etc.
Let's jump straight into an example.

x <- 1 : 24
y <- array(dim=c(2,2,6))

I would like to have:
y[1,1,1] = 1
y[1,1,2] = 2
...
y[1,1,6] = 6
y[1,2,1] = 7
y[1,2,2] = 8
...
y[2,1,1] = 13
...
y[2,2,1] = 19

if I do y<- array(x, dim=c(2,2,6)), i think I will get
y[1,1,1] = 1
y[2,1,1] = 2
(or something not I want) instead.

Of course, I need a fast solution, as I am actually dealing with array of much larger size.
Any input will be appreciated
Thanks a lot


More information about the R-help mailing list