permutation.Rd
Row and/or column permutes a (sparse) matrix.
permutation.spam(A, P=NULL, Q=NULL, ind=FALSE, check=TRUE)
sparse matrix
vector giving the row permutation.
vector giving the column permutation.
are the indices given. See examples.
Should rudimentary checks be performed.
A permuted matrix.
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.
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)