Learn R Programming

seriation (version 1.1-1)

permute: Permute a dist Object, a Matrix, an Array, a List, or a Vector

Description

A method for permuting various classes including the observations in a dist object, the rows and columns of a matrix, and 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.

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).

See Also

ser_permutation, dist in package stats.

Examples

Run this code
## 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 dist
d <- dist(m)
d

permute(d, ser_permutation(c(3,2,1,4,5)))

## permute list
l <- list(a=1:5, b=letters[1:3], c=0)
l
  
permute(l, c(2,3,1))

Run the code above in your browser using DataLab