Matrix-class             package:Matrix             R Documentation

_V_i_r_t_u_a_l _C_l_a_s_s "_M_a_t_r_i_x" _C_l_a_s_s _o_f _M_a_t_r_i_c_e_s

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

     The 'Matrix' class is a class contained by all actual classes in
     the 'Matrix' package.  It is a virtual class.

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

     Common to _all_ matrix objects in the package:

     '_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': list of length two; each component containing NULL or
          a 'character' vector length equal the corresponding 'Dim'
          element.

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


     _d_i_f_f 'signature(x = "Matrix")': As 'diff()' for traditional
          matrices, i.e., applying 'diff()' to each column.

     _d_i_m 'signature(x = "Matrix")': extract matrix dimensions 'dim'.

     _d_i_m<- 'signature(x = "Matrix", value = "ANY")': where 'value' is
          integer of length 2.  Allows to _reshape_ Matrix objects, but
          only when 'prod(value) == prod(dim(x))'.

     _d_i_m_n_a_m_e_s 'signature(x = "Matrix")': extract 'dimnames'.

     _d_i_m_n_a_m_e_s<- 'signature(x = "Matrix", value = "list")': set the
          'dimnames' to a 'list' of length 2, see 'dimnames<-'.

     _l_e_n_g_t_h 'signature(x = "Matrix")': simply defined as 'prod(dim(x))'
          (and hence of mode '"double"').

     _s_h_o_w 'signature(object = "Matrix")': 'show' method for 'print'ing.

     _i_m_a_g_e 'signature(object = "Matrix")': draws an 'image' of the
          matrix entries, using 'levelplot()' from package 'lattice'.

     _h_e_a_d 'signature(object = "Matrix")': return only the _head_,
          i.e., the first few rows.

     _t_a_i_l 'signature(object = "Matrix")': return only the _tail_,
          i.e., the last few rows of the respective matrix. 


     _a_s._m_a_t_r_i_x, _a_s._a_r_r_a_y 'signature(x = "Matrix")': the same as 'as(x,
          "matrix")'; see also the note below.

     _a_s._v_e_c_t_o_r 'signature(x = "Matrix", mode = "missing")':
          'as.vector(m)' should be identical to 'as.vector(as(m,
          "matrix"))', implemented more efficiently for some
          subclasses.

     _a_s(_x, "_v_e_c_t_o_r"), _a_s(_x, "_n_u_m_e_r_i_c") etc, similarly.

     There are many more methods that (conceptually should) work for
     all '"Matrix"' objects, e.g., 'colSums', 'rowMeans'.  Even 'base'
     functions may work automagically (if they first call 'as.matrix()'
     on their principal argument), e.g., 'apply', 'eigen', 'svd' or
     'kappa' all do work via coercion to a traditional (dense)
     'matrix'.

_N_o_t_e:

     Loading the 'Matrix' namespace overloads 'as.matrix' and
     'as.array' in the 'base' namespace by the equivalent of
     'function(x) as(x, "matrix")'. Consequently, 'as.matrix(m)' or
     'as.array(m)' will properly work when 'm' inherits from the
     '"Matrix"' class - _also_ for functions in package 'base' and
     other packages. E.g., 'apply' or 'outer' can therefore be applied
     to '"Matrix"' matrices.

_A_u_t_h_o_r(_s):

     Douglas Bates bates@stat.wisc.edu and Martin Maechler

_S_e_e _A_l_s_o:

     the classes 'dgeMatrix', 'dgCMatrix', and function 'Matrix' for
     construction (and examples).

     Methods, e.g., for 'kronecker'.

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

     slotNames("Matrix")

     cl <- getClass("Matrix")
     names(cl@subclasses) # more than 40 ..

     showClass("Matrix")#> output with slots and all subclasses

     (M <- Matrix(c(0,1,0,0), 6, 4))
     dim(M)
     diag(M)
     diff(M)
     ## can reshape it even :
     dim(M) <- c(2, 12)
     M
     stopifnot(identical(M, Matrix(c(0,1,0,0), 2,12)))

