aperm(a, perm)

Permute the dimensions of an array.

- a – An array.
- perm – A permutation of the numbers 1:k, where k is the number of dimensions in array a. The default permutation is k:1.

Example. A simple array a is initialized with values 1 through 12. Array b is a permutation of a where the second dimension of a is the first dimension of b, and so on. Finally, we verify the permutation worked as expected.

> a <- array(1:(2*2*3), c(2,2,3)) > perm <- c(2,3,1) > b <- aperm(a, perm) > > a[1,2,3] [1] 11 > c(1,2,3)[perm] [1] 2 3 1 > b[2,3,1] [1] 11 > > a[2,2,1] [1] 4 > c(2,2,1)[perm] [1] 2 1 2 > b[2,1,2] [1] 4