Return the matrix obtained by setting to zero elements below a diagonal
triu), above a diagonal (
tril), or outside of a general
band(x, k1, k2, ...) triu(x, k = 0, ...) tril(x, k = 0, ...)
a matrix-like object
integers specifying the diagonals that are not set to
zero. These are interpreted relative to the main diagonal, which
optional arguments passed methods (currently unused by package Matrix)
triu(x, k) is equivalent to
band(x, k, dim(x)).
tril(x, k) is equivalent to
band(x, -dim(x), k).
An object of a suitable matrix class, inheriting from
triangularMatrix where appropriate.
It inherits from
and only if
method for compressed, sparse, column-oriented matrices.
method for compressed, sparse, row-oriented matrices.
method for sparse matrices in triplet format.
method for diagonal matrices.
method for dense matrices in packed or unpacked format.
method for traditional matrices
of implicit class
bandSparse for the construction of a
banded sparse matrix directly from its non-zero diagonals.
## 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), ncol = 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), ncol = 5)) # not square triu(m65) # result not "dtrMatrix" unless square (sm5 <- crossprod(m65)) # symmetric band(sm5, -1, 1)# "dsyMatrix": symmetric band preserves symmetry property as(band(sm5, -1, 1), "sparseMatrix")# often preferable (sm <- round(crossprod(triu(mm/2)))) # sparse symmetric ("dsC*") band(sm, -1,1) # remains "dsC", *however* band(sm, -2,1) # -> "dgC"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.