| permute | 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, ...)
## S3 method for class 'array'
permute(x, order, margin = NULL, ...)
## S3 method for class 'matrix'
permute(x, order, margin = NULL, ...)
## S3 method for class 'data.frame'
permute(x, order, margin = NULL, ...)
## S3 method for class 'table'
permute(x, order, margin = NULL, ...)
## S3 method for class 'numeric'
permute(x, order, ...)
## S3 method for class 'character'
permute(x, order, ...)
## S3 method for class 'list'
permute(x, order, ...)
## S3 method for class 'dist'
permute(x, order, ...)
## S3 method for class 'dendrogram'
permute(x, order, dist = NULL, ...)
## S3 method for class 'hclust'
permute(x, order, dist = NULL, ...)
x |
an object (a list, a vector, a |
order |
an object of class ser_permutation which contains
suitable permutation vectors for |
... |
if |
margin |
specifies the dimensions to be permuted as a vector with dimension indices.
If |
dist |
the distance matrix used to create the dendrogram. Only needed if order is the name of a seriation method. |
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 dendrogram and hclust, subtrees are rotated to represent
the order best possible. If the order is not achieved perfectly then the
user is warned. See also reorder.hclust() for
reordering hclust objects.
A permuted object of the same class as x.
Michael Hahsler
Other permutation:
get_order(),
permutation_vector2matrix(),
ser_dist(),
ser_permutation(),
ser_permutation_vector()
# 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)
o
permute(m, o)
## permute only columns
permute(m, o, margin = 2)
## permute using PCA seriation
permute(m, "PCA")
## permute only rows using PCA
permute(m, "PCA", margin = 1)
# Permute data.frames using heatmap seration (= hierarchical
# clustering + optimal leaf ordering)
df <- as.data.frame(m)
permute(df, "Heatmap")
# Permute objects in a dist object
d <- dist(m)
d
permute(d, c(3, 2, 1, 4, 5))
permute(d, "Spectral")
# Permute a list
l <- list(a = 1:5, b = letters[1:3], c = 0)
l
permute(l, c(2, 3, 1))
# Permute to reorder dendrogram (see also reorder.hclust)
hc <- hclust(d)
plot(hc)
plot(permute(hc, 5:1))
plot(permute(hc, 5:1, incompartible = "stop"))
plot(permute(hc, "OLO", dist = d))
plot(permute(hc, "GW", dist = d))
plot(permute(hc, "MDS", dist = d))
plot(permute(hc, "TSP", dist = d))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.