spam (version 2.5-1)

permutation: Permute a matrix

Description

Row and/or column permutes a matrix.

Usage

permutation.spam(A, P=NULL, Q=NULL, ind=FALSE, check=TRUE)

Arguments

A

sparse matrix

P

vector giving the row permutation.

Q

vector giving the column permutation.

ind

are the indices given. See examples.

check

Should rudimentary checks be performed.

Value

A permuted matrix.

Details

If P and Q are permutation matrices, the result is PAQ. However, it is also possible to specify the indices and to perform in a very efficient way A[rowind, colind], see examples.

A row permutation is much faster than a colum permutation. For very large matrices, a double transpose might be faster.

The spam option spam.checkpivot determines if the permutation is verified.

See Also

ordering, spam.options.

Examples

Run this code
# NOT RUN {
A <- spam(1:12,3)
P <- c(3,1,2)
Q <- c(2,3,1,4)

permutation(A,P,Q)-A[order(P),order(Q)]

permutation(A,P,Q,ind=TRUE)-A[P,Q]

# }

Run the code above in your browser using DataLab