sparseVector-class package:Matrix R Documentation _S_p_a_r_s_e _V_e_c_t_o_r _C_l_a_s_s_e_s _D_e_s_c_r_i_p_t_i_o_n: Sparse Vector Classes: The virtual mother class '"sparseVector"' has the five actual daughter classes '"dsparseVector"', '"isparseVector"', '"lsparseVector"', '"nsparseVector"', and '"zsparseVector"', where we've mainly implemented methods for the 'd*', 'l*' and 'n*' ones. _S_l_o_t_s: '_l_e_n_g_t_h': class '"integer"' - the 'length' of the sparse vector. '_i': class '"integer"' - the (1-based) indices of the non-zero entries. '_x': (for all but '"nsparseVector"'): the non-zero entries. This is of class '"numeric"' for class '"dsparseVector"', '"logical"' for class '"lsparseVector"', etc. Note that '"nsparseVector"'s have no 'x' slot. Further, mainly for ease of method definitions, we've defined the class union (see 'setClassUnion') of all sparse vector classes which _have_ an 'x' slot, as class '"xsparseVector"'. _M_e_t_h_o_d_s: _l_e_n_g_t_h 'signature(x = "sparseVector")': simply extracts the 'length' slot. _s_h_o_w 'signature(object = "sparseVector")': The 'show' method for sparse vectors prints _"structural"_ zeroes as '"."' using the non-exported 'prSpVector' function which allows further customization such as replacing '"."' by '" "' (blank). Note that 'options(max.print)' will influence how many entries of large sparse vectors are printed at all. _a_s._v_e_c_t_o_r 'signature(x = "sparseVector", mode = "character")' coerces sparse vectors to "regular", i.e., atomic vectors. This is the same as 'as(x, "vector")'. _d_i_m<- 'signature(x = "sparseVector", value = "integer")' coerces a sparse vector to a sparse Matrix, i.e., an object inheriting from 'sparseMatrix', of the appropriate dimension. _r_e_p 'signature(x = "sparseVector")' repeat 'x', with the same argument list '(x, times, length.out, each, ...)' as the default method for rep(). _E_x_a_m_p_l_e_s: getClass("sparseVector") getClass("dsparseVector") getClass("xsparseVector")# those with an 'x' slot sx <- c(0,0,3, 3.2, 0,0,0,-3:1,0,0,2,0,0,5,0,0) (ss <- as(sx, "sparseVector")) ix <- as.integer(round(sx)) (is <- as(ix, "sparseVector")) ## an "isparseVector" (!) ## rep() works too: rep(is, length.out= 25) ## Using `dim<-` as in base R : r <- ss dim(r) <- c(4,5) # becomes a sparse Matrix: r