pMatrix-class             package:Matrix             R Documentation

_P_e_r_m_u_t_a_t_i_o_n _m_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

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

_O_b_j_e_c_t_s _f_r_o_m _t_h_e _C_l_a_s_s:

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

_S_l_o_t_s:

     '_p_e_r_m': An integer, 1-based permutation vector, i.e. an integer
          vector of length 'Dim[1]' whose elements form a permutation
          of '1:Dim[1]'.

     '_D_i_m': Object of class '"integer"'. The dimensions of the matrix
          which must be a two-element vector of equal, non-negative
          integers.

     '_D_i_m_n_a_m_e_s': list of length two; each component containing NULL or
          a 'character' vector length equal the corresponding 'Dim'
          element.

_E_x_t_e_n_d_s:

     Class '"Matrix"', directly.

_M_e_t_h_o_d_s:

     %*% 'signature(x = "matrix", y = "pMatrix")' and other signatures
          (use 'showMethods("%*%", class="pMatrix")'): ... 

     _c_o_e_r_c_e 'signature(from = "integer", to = "pMatrix")': This is
          enables typical '"pmatrix"' construction, given a permutation
          vector of '1:n', see the first example.

     _c_o_e_r_c_e 'signature(from = "pMatrix", to = "matrix")': ... 

     _s_o_l_v_e 'signature(a = "pMatrix", b = "missing")': return the
          inverse permutation matrix.

     _t 'signature(x = "pMatrix")': return the transpose of the
          permuation matrix (which is also the inverse of the
          permutation matrix).

_E_x_a_m_p_l_e_s:

     (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

