Row and/or column permutes a (sparse) matrix.

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

Author

Reinhard Furrer

Examples

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)]
#>      [,1] [,2] [,3] [,4]
#> [1,]    0    0    0    0
#> [2,]    0    0    0    0
#> [3,]    0    0    0    0
#> Class 'spam' (32-bit)

permutation(A,P,Q,ind=TRUE)-A[P,Q]
#>      [,1] [,2] [,3] [,4]
#> [1,]    0    0    0    0
#> [2,]    0    0    0    0
#> [3,]    0    0    0    0
#> Class 'spam' (32-bit)