Array Permutations

DESCRIPTION:
Permutes the dimensions of an array. Optionally, the shape of the array can be held constant while the dimensions are changed.

USAGE:
aperm(a, perm=<<see below>>, reshape=T)

REQUIRED ARGUMENTS:
a:
array to be permuted. Missing values (NAs) are allowed.

OPTIONAL ARGUMENTS:
perm:
vector containing a permutation of the integers 1:n where n is the number of dimensions in the array a, that is, n==length(dim(a)). The old dimension given by perm[j] becomes the new j-th dimension. If perm is missing, the dimensions are reversed, i.e., perm=n:1.
reshape:
a logical flag. If TRUE, the dimensions of the result are changed to correspond with the re-ordering. If FALSE, the dimensions of the result are the same as the dimensions of a.

VALUE:
array like a, but with the observations permuted according to perm, e.g., if perm is c(2,1,3), the result will be an array in which the old second dimension is the new first dimension, etc.

DETAILS:
aperm is a generic function with a default method and a method for data frames (which performs as.matrix on the data frame and then does aperm.default).

For arrays a dimnames attribute, if present, will be appropriately permuted, but names, if present, will be deleted.


SEE ALSO:
t for the transpose of a matrix.

EXAMPLES:
  # turns 50 x 4 x 3 into 50 x 3 x 4
myiris <- aperm(iris,c(1,3,2))
  # make 150 x 4 matrix
myiris <- matrix(aperm(iris,c(1,3,2)),150,4)

# if bar is a matrix created from a file in the wrong order # (byrow was not set to TRUE), then the following sets it right t(aperm(t(bar),reshape=F))