Matrix (version 0.99-3)

pMatrix-class: Permutation matrices

Description

The "pMatrix" class is the class of permutation matrices, stored as 1-based integer permutation vectors.

Arguments

Objects from the Class

Objects can be created by calls of the form new("pMatrix", ...) or by coercion from an integer permutation vector, see below.

Extends

Class "Matrix", directly.

Examples

Run this code
(pm1 <- as(as.integer(c(2,3,1)), "pMatrix"))
t(pm1) # is the same as
solve(pm1)
pm1 %*% t(pm1) # check that the transpose is the inverse
stopifnot(identical(diag(3), as(pm1 %*% t(pm1), "matrix")))
(mm <- round(array(rnorm(3 * 3), c(3, 3)), 2))
mm %*% pm1
pm1 %*% mm
try(as(as.integer(c(3,3,1)), "pMatrix"))# Error: not a permutation

as(pm1, "lgTMatrix")

Run the code above in your browser using DataLab