drop0                 package:Matrix                 R Documentation

_D_r_o_p "_E_x_p_l_i_c_i_t _Z_e_r_o_e_s" _f_r_o_m _a _S_p_a_r_s_e _M_a_t_r_i_x

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

     Returns a sparse matrix with no explicit zeroes, i.e., all zero
     or 'FALSE' entries are dropped from the explicitly indexed matrix
     entries.

_U_s_a_g_e:

     drop0(x, tol = 0, is.Csparse = NA)

_A_r_g_u_m_e_n_t_s:

       x: a Matrix, typically sparse, i.e., inheriting from
          'sparseMatrix'.

     tol: non-negative number to be used as tolerance for checking if
          an entry x[i,j] should be considered to be zero.

is.Csparse: logical indicating prior knowledge about the Csparseness
          of 'x'.  This exists for possible speedup reasons only.

_V_a_l_u_e:

     a Matrix like 'x' but with no explicit zeros, i.e., '!any(x@x ==
     0)', always inheriting from 'CsparseMatrix'.

_N_o_t_e:

     When a sparse matrix is the result of matrix multiplications, you
     may want to consider combining 'drop0()' with 'zapsmall()', see
     the example.

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

     'spMatrix', class 'sparseMatrix'

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

     m <- spMatrix(10,20, i= 1:8, j=2:9,
                   x = c(0:2,3:-1))
     m
     drop0(m)

     ## A larger example:
     t5 <- new("dtCMatrix", Dim = c(5L, 5L), uplo = "L",
               x = c(10, 1, 3, 10, 1, 10, 1, 10, 10),
               i = c(0L,2L,4L, 1L, 3L,2L,4L, 3L, 4L),
               p = c(0L, 3L, 5L, 7:9))
     TT <- kronecker(t5, kronecker(kronecker(t5,t5), t5))
     IT <- solve(TT)
     I. <- TT %*% IT ;  nnzero(I.) # 697 ( = 625 + 72 )
     I.0 <- drop0(zapsmall(I.))
     stopifnot(all(I.0 == Diagonal(625)))

