band                 package:Matrix                 R Documentation

_E_x_t_r_a_c_t _b_a_n_d_s _o_f _a _m_a_t_r_i_x

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

     Returns a new matrix formed by extracting the lower triangle
     ('tril') or the upper triangle ('triu') or a general band relative
     to the diagonal ('band'), and setting other elements to zero.  The
     general forms of these functions include integer arguments to
     specify how many diagonal bands above or below the main diagonal
     are not set to zero.

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

     band(x, k1, k2, ...)
     tril(x, k = 0, ...)
     triu(x, k = 0, ...)

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

       x: a matrix-like object

 k,k1,k2: integers specifying the diagonal bands that will not be set
          to zero.  These are given relative to the main diagonal,
          which is 'k=0'.  A negative value of 'k' indicates a diagonal
          below the main diagonal and a positive value indicates a
          diagonal above the main diagonal.

     ...: Optional arguments used by specific methods. (None used at
          present.)

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

     An object of an appropriate matrix class.  The class of the value
     of 'tril' or 'triu' inherits from 'triangularMatrix' when
     appropriate.  Note that the result is of class 'sparseMatrix' only
     if 'x' is.

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


     _x = "_C_s_p_a_r_s_e_M_a_t_r_i_x" method for compressed, sparse, column-oriented
          matrices.

     _x = "_T_s_p_a_r_s_e_M_a_t_r_i_x" method for sparse matrices in triplet format.

     _x = "_R_s_p_a_r_s_e_M_a_t_r_i_x" method for compressed, sparse, row-oriented
          matrices.

     _x = "_d_d_e_n_s_e_M_a_t_r_i_x" method for dense numeric matrices, including
          packed numeric matrices.

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

     'bandSparse' for the _construction_ of a banded sparse matrix
     directly from its non-zero diagonals.

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

     ## A random sparse matrix :
     set.seed(7)
     m <- matrix(0, 5, 5)
     m[sample(length(m), size = 14)] <- rep(1:9, length=14)
     (mm <- as(m, "CsparseMatrix"))

     tril(mm)        # lower triangle
     tril(mm, -1)    # strict lower triangle
     triu(mm,  1)    # strict upper triangle
     band(mm, -1, 2) # general band
     (m5 <- Matrix(rnorm(25), nc = 5))
     tril(m5)        # lower triangle
     tril(m5, -1)    # strict lower triangle
     triu(m5, 1)     # strict upper triangle
     band(m5, -1, 2) # general band
     (m65 <- Matrix(rnorm(30), nc = 5))  # not square
     triu(m65)       # result in not dtrMatrix unless square
     (sm5 <- crossprod(m65)) # symmetric
        band(sm5, -1, 1)# symmetric band preserves symmetry property
     as(band(sm5, -1, 1), "sparseMatrix")# often preferable

