aperm(a, perm=<<see below>>, reshape=T)
NA
s) are allowed.
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.
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
.
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.
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.
# 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))