Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

permute

Permute the Order in Various Objects


Description

Provides the generic function and methods for permuting the order of various objects including vectors, dendrograms (also hclust objects), the order of observations in a dist object, the rows and columns of a matrix, all dimensions of an array given a suitable ser_permutation object.

Usage

permute(x, order, ...)

Arguments

x

an object (a list, a vector, a dist object, a matrix, an array or any other object which provides dim and standard subsetting with "[").

order

an object of class ser_permutation which contains suitable permutation vectors for x.

...

additional arguments for the permutation function.

Details

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 dendrograms and hclust, subtrees are rotated to represent the order best possible. If the order is not achived 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".

Author(s)

Michael Hahsler

See Also

ser_permutation, dist in package stats.

Examples

## permute matrix
m <- matrix(rnorm(10), 5, 2, dimnames = list(1:5, 1:2))
m

## permute rows and columns
permute(m, ser_permutation(5:1, 2:1))
## permute only columns
permute(m, ser_permutation(NA, 2:1))
  
## 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))

seriation

Infrastructure for Ordering Objects Using Seriation

v1.2-9
GPL-3
Authors
Michael Hahsler [aut, cre, cph], Christian Buchta [aut, cph], Kurt Hornik [aut, cph], Fionn Murtagh [ctb, cph], Michael Brusco [ctb, cph], Stephanie Stahl [ctb, cph], Hans-Friedrich Koehn [ctb, cph]
Initial release
2020-09-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.