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)))