| permute {seriation} | R Documentation |
Provides the generic function and
methods for permuting the order of various objects
including vectors, lists, dendrograms (also hclust objects),
the order of observations in a dist object,
the rows and columns of a matrix or data.frame, and
all dimensions of an array given a suitable ser_permutation object.
permute(x, order, ...)
x |
an object (a list, a vector, a |
order |
an object of class |
... |
additional arguments for the permutation function. |
The permutation vectors in ser_permutation
are suitable if the number of permutation vectors matches the number
of dimensions of x and if the length of each permutation vector
has the same length as the corresponding dimension of x.
For 1-dimensional/1-mode data (list, vector, dist),
order can also be a single
permutation vector of class ser_permutation_vector or data which can be
automatically coerced to this class
(e.g. a numeric vector).
For matrix-like objects, the additional parameter margin can be specified to permute
only a single dimension. In this case, order can be a single permutation vector or a complete
liis with pemutations for all dimensions. In the latter case, all permutations but the one specified in
margin are ignored.
For dendrograms and hclust, subtrees are rotated to
represent the order best possible. If the order is not achieved perfectly
then the user is warned. This behavior can be changed with the extra
parameter incompatible which can take the values
"warn" (default), "stop" or "ignore".
Michael Hahsler
ser_permutation,
dist in package stats.
# List data types for permute
methods("permute")
# Permute matrix
m <- matrix(rnorm(10), 5, 2, dimnames = list(1:5, LETTERS[1:2]))
m
# Permute rows and columns
o <- ser_permutation(5:1, 2:1)
permute(m, o)
## permute only columns
permute(m, o, margin = 2)
df <- as.data.frame(m)
permute(df, o)
# Permute objects in a dist object
d <- dist(m)
d
permute(d, ser_permutation(c(3,2,1,4,5)))
# Permute a list
l <- list(a=1:5, b=letters[1:3], c=0)
l
permute(l, c(2,3,1))
# Permute a dendrogram
hc <- hclust(d)
plot(hc)
plot(permute(hc, 5:1))