Learn R Programming

vcdExtra (version 0.5-2)

aperm: Array Transposition

Description

Transpose an array or table by permuting its dimensions and optionally resizing it. These functions extend aperm to handle table objects, and will be withdrawn when the base functions are similarly extended.

Usage

aperm(a, ...)

## S3 method for class 'default':
aperm(a, perm, resize = TRUE, ...)

## S3 method for class 'table':
aperm(a, perm, resize = TRUE, keep.class = TRUE, ...)

Arguments

a
the array or table object to be transposed
perm
the subscript permutation vector, which must be a permutation of the integers 1:n, where n is the number of dimensions of a. The default is to reverse the order of the dimensions.
resize
a flag indicating whether the vector should be resized as well as having its elements reordered (default TRUE).
keep.class
a flag indicating whether the result should be assigned the same class as a (default TRUE).
...
arguments passed to methods

Value

  • A transposed version of array a, with subscripts permuted as indicated by the vector perm. If resize is TRUE, the array is reshaped as well as having its elements permuted, the dimnames are also permuted; if resize = FALSE then the returned object has the same dimensions as a, and the dimnames are dropped. In each case other attributes are copied from a.

See Also

t, to transpose matrices. aperm, table

Examples

Run this code
# interchange the first two subscripts on a 3-way array x
x  <- array(1:24, 2:4)
xt <- aperm(x, c(2,1,3))
stopifnot(t(xt[,,2]) == x[,,2],
          t(xt[,,3]) == x[,,3],
          t(xt[,,4]) == x[,,4])

# table objects
str(UCBAdmissions)
UCB <- aperm(UCBAdmissions, c(2, 1, 3))
str(UCB)

Run the code above in your browser using DataLab