sparseMatrix-class          package:Matrix          R Documentation

_V_i_r_t_u_a_l _C_l_a_s_s "_s_p_a_r_s_e_M_a_t_r_i_x" - _M_o_t_h_e_r _o_f _S_p_a_r_s_e _M_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Virtual Mother Class of All Sparse Matrices

_S_l_o_t_s:


     '_D_i_m': Object of class '"integer"' - the dimensions of the matrix
          - must be an integer vector with exactly two non-negative
          values.

     '_D_i_m_n_a_m_e_s': a list of length two - inherited from class 'Matrix',
          see 'Matrix'.

_E_x_t_e_n_d_s:

     Class '"Matrix"', directly.

_M_e_t_h_o_d_s:


     _s_h_o_w '(object = "sparseMatrix")': The 'show' method for sparse
          matrices prints _"structural"_ zeroes as '"."' using
          'printSpMatrix()' which allows further customization.

     _p_r_i_n_t 'signature(x = "sparseMatrix")', ....
           The 'print' method for sparse matrices by default is the
          same as 'show()' but can be called with extra optional
          arguments, see 'printSpMatrix()'.

     _s_u_m_m_a_r_y '(object = "sparseMatrix")': Returns an object of S3 class
          '"sparseSummary"' which is basically a 'data.frame' with
          columns '(i,j,x)' (or just '(i,j)' for 'nsparseMatrix' class
          objects) with the stored (typically non-zero) entries.  The
          'print' method resembles Matlab's way of printing sparse
          matrices, and also the MatrixMarket format, see 'writeMM'.

     _d_e_t_e_r_m_i_n_a_n_t '(x = "sparseMatrix", logarithm=TRUE)':
          'determinant()' methods for sparse matrices typically work
          via 'Cholesky' or 'lu' decompositions.

     _d_i_a_g '(x = "sparseMatrix")': extracts the diagonal of a sparse
          matrix.

     _d_i_m<- 'signature(x = "sparseMatrix", value = "ANY")': allows to
          _reshape_ a sparse matrix to a sparse matrix with the same
          entries but different dimensions. 'value' must be of length
          two and fulfill 'prod(value) == prod(dim(x))'.

     _c_o_e_r_c_e 'signature(from = "factor", to = "sparseMatrix")': Coercion
          of a factor to '"sparseMatrix"' produces the matrix of
          indicator *rows* stored as an object of class '"dgCMatrix"'. 
          To obtain columns representing the interaction of the factor
          and a numeric covariate, replace the '"x"' slot of the result
          by the numeric covariate then take the transpose. Missing
          values ('NA') from the factor are translated to columns of
          all '0's.

     See also 'colSums', 'norm', ...  for methods with separate help
     pages.

_N_o_t_e:

     In method selection for multiplication operations (i.e. '%*%' and
     the two-argument form of 'crossprod') the sparseMatrix class takes
     precedence in the sense that if one operand is a sparse matrix and
     the other is any type of dense matrix then the dense matrix is
     coerced to a 'dgeMatrix' and the appropriate sparse matrix method
     is used.

_E_x_a_m_p_l_e_s:

     showClass("sparseMatrix") ## and look at the help() of its subclasses
     M <- Matrix(0, 10000, 100)
     M[1,1] <- M[2,3] <- 3.14
     M  ## show(.) method suppresses printing of the majority of rows

     data(CAex); dim(CAex) # 72 x 72 matrix
     determinant(CAex) # works via sparse lu(.)

     ## factor -> t( <sparse design matrix> ) :
     (fact <- gl(5, 3, 30, labels = LETTERS[1:5]))
     (Xt <- as(fact, "sparseMatrix"))  # indicator rows

     ## missing values --> all-0 columns:
     f.mis <- fact
     i.mis <- c(3:5, 17)
     is.na(f.mis) <- i.mis
     Xt != (X. <- as(f.mis, "sparseMatrix")) # differ only in columns 3:5,17
     stopifnot(all(X.[,i.mis] == 0), all(Xt[,-i.mis] == X.[,-i.mis]))

