\HeaderA{band}{Extract bands of a matrix}{band}
\aliasA{band,CsparseMatrix-method}{band}{band,CsparseMatrix.Rdash.method}
\aliasA{band,ddenseMatrix-method}{band}{band,ddenseMatrix.Rdash.method}
\aliasA{band,denseMatrix-method}{band}{band,denseMatrix.Rdash.method}
\aliasA{band,matrix-method}{band}{band,matrix.Rdash.method}
\aliasA{band,RsparseMatrix-method}{band}{band,RsparseMatrix.Rdash.method}
\aliasA{band,TsparseMatrix-method}{band}{band,TsparseMatrix.Rdash.method}
\aliasA{band-methods}{band}{band.Rdash.methods}
\aliasA{tril}{band}{tril}
\aliasA{tril,CsparseMatrix-method}{band}{tril,CsparseMatrix.Rdash.method}
\aliasA{tril,ddenseMatrix-method}{band}{tril,ddenseMatrix.Rdash.method}
\aliasA{tril,denseMatrix-method}{band}{tril,denseMatrix.Rdash.method}
\aliasA{tril,dsCMatrix-method}{band}{tril,dsCMatrix.Rdash.method}
\aliasA{tril,dtCMatrix-method}{band}{tril,dtCMatrix.Rdash.method}
\aliasA{tril,dtpMatrix-method}{band}{tril,dtpMatrix.Rdash.method}
\aliasA{tril,dtRMatrix-method}{band}{tril,dtRMatrix.Rdash.method}
\aliasA{tril,dtrMatrix-method}{band}{tril,dtrMatrix.Rdash.method}
\aliasA{tril,dtTMatrix-method}{band}{tril,dtTMatrix.Rdash.method}
\aliasA{tril,itCMatrix-method}{band}{tril,itCMatrix.Rdash.method}
\aliasA{tril,itRMatrix-method}{band}{tril,itRMatrix.Rdash.method}
\aliasA{tril,itTMatrix-method}{band}{tril,itTMatrix.Rdash.method}
\aliasA{tril,lsCMatrix-method}{band}{tril,lsCMatrix.Rdash.method}
\aliasA{tril,ltCMatrix-method}{band}{tril,ltCMatrix.Rdash.method}
\aliasA{tril,ltpMatrix-method}{band}{tril,ltpMatrix.Rdash.method}
\aliasA{tril,ltRMatrix-method}{band}{tril,ltRMatrix.Rdash.method}
\aliasA{tril,ltrMatrix-method}{band}{tril,ltrMatrix.Rdash.method}
\aliasA{tril,ltTMatrix-method}{band}{tril,ltTMatrix.Rdash.method}
\aliasA{tril,matrix-method}{band}{tril,matrix.Rdash.method}
\aliasA{tril,nsCMatrix-method}{band}{tril,nsCMatrix.Rdash.method}
\aliasA{tril,ntCMatrix-method}{band}{tril,ntCMatrix.Rdash.method}
\aliasA{tril,ntpMatrix-method}{band}{tril,ntpMatrix.Rdash.method}
\aliasA{tril,ntRMatrix-method}{band}{tril,ntRMatrix.Rdash.method}
\aliasA{tril,ntrMatrix-method}{band}{tril,ntrMatrix.Rdash.method}
\aliasA{tril,ntTMatrix-method}{band}{tril,ntTMatrix.Rdash.method}
\aliasA{tril,RsparseMatrix-method}{band}{tril,RsparseMatrix.Rdash.method}
\aliasA{tril,TsparseMatrix-method}{band}{tril,TsparseMatrix.Rdash.method}
\aliasA{tril-methods}{band}{tril.Rdash.methods}
\aliasA{triu}{band}{triu}
\aliasA{triu,CsparseMatrix-method}{band}{triu,CsparseMatrix.Rdash.method}
\aliasA{triu,ddenseMatrix-method}{band}{triu,ddenseMatrix.Rdash.method}
\aliasA{triu,denseMatrix-method}{band}{triu,denseMatrix.Rdash.method}
\aliasA{triu,dsCMatrix-method}{band}{triu,dsCMatrix.Rdash.method}
\aliasA{triu,dtCMatrix-method}{band}{triu,dtCMatrix.Rdash.method}
\aliasA{triu,dtpMatrix-method}{band}{triu,dtpMatrix.Rdash.method}
\aliasA{triu,dtRMatrix-method}{band}{triu,dtRMatrix.Rdash.method}
\aliasA{triu,dtrMatrix-method}{band}{triu,dtrMatrix.Rdash.method}
\aliasA{triu,dtTMatrix-method}{band}{triu,dtTMatrix.Rdash.method}
\aliasA{triu,itCMatrix-method}{band}{triu,itCMatrix.Rdash.method}
\aliasA{triu,itRMatrix-method}{band}{triu,itRMatrix.Rdash.method}
\aliasA{triu,itTMatrix-method}{band}{triu,itTMatrix.Rdash.method}
\aliasA{triu,lsCMatrix-method}{band}{triu,lsCMatrix.Rdash.method}
\aliasA{triu,ltCMatrix-method}{band}{triu,ltCMatrix.Rdash.method}
\aliasA{triu,ltpMatrix-method}{band}{triu,ltpMatrix.Rdash.method}
\aliasA{triu,ltRMatrix-method}{band}{triu,ltRMatrix.Rdash.method}
\aliasA{triu,ltrMatrix-method}{band}{triu,ltrMatrix.Rdash.method}
\aliasA{triu,ltTMatrix-method}{band}{triu,ltTMatrix.Rdash.method}
\aliasA{triu,matrix-method}{band}{triu,matrix.Rdash.method}
\aliasA{triu,nsCMatrix-method}{band}{triu,nsCMatrix.Rdash.method}
\aliasA{triu,ntCMatrix-method}{band}{triu,ntCMatrix.Rdash.method}
\aliasA{triu,ntpMatrix-method}{band}{triu,ntpMatrix.Rdash.method}
\aliasA{triu,ntRMatrix-method}{band}{triu,ntRMatrix.Rdash.method}
\aliasA{triu,ntrMatrix-method}{band}{triu,ntrMatrix.Rdash.method}
\aliasA{triu,ntTMatrix-method}{band}{triu,ntTMatrix.Rdash.method}
\aliasA{triu,RsparseMatrix-method}{band}{triu,RsparseMatrix.Rdash.method}
\aliasA{triu,TsparseMatrix-method}{band}{triu,TsparseMatrix.Rdash.method}
\aliasA{triu-methods}{band}{triu.Rdash.methods}
\keyword{methods}{band}
\keyword{algebra}{band}
\begin{Description}\relax
Returns a new matrix formed by extracting the lower triangle
(\code{tril}) or the upper triangle (\code{triu}) or a general band
relative to the diagonal (\code{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.
\end{Description}
\begin{Usage}
\begin{verbatim}
band(x, k1, k2, ...)
tril(x, k = 0, ...)
triu(x, k = 0, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a matrix-like object
\item[\code{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 \code{k=0}.  A negative value of \code{k} indicates a
diagonal below the main diagonal and a positive value indicates a
diagonal above the main diagonal.
\item[\code{...}] Optional arguments used by specific methods. (None used at present.)
\end{ldescription}
\end{Arguments}
\begin{Value}
An object of an appropriate matrix class.  The class of the value of
\code{tril} or \code{triu} inherits from
\code{\LinkA{triangularMatrix}{triangularMatrix.Rdash.class}} when appropriate.  Note that the
result is of class \code{\LinkA{sparseMatrix}{sparseMatrix.Rdash.class}} only if \code{x} is.
\end{Value}
\begin{Section}{Methods}
\describe{
\item[x = "CsparseMatrix"] method for compressed, sparse,
column-oriented matrices.
\item[x = "TsparseMatrix"] method for sparse matrices in triplet format.
\item[x = "RsparseMatrix"] method for compressed, sparse,
row-oriented matrices.
\item[x = "ddenseMatrix"] method for dense numeric matrices,
including packed numeric matrices.
}
\end{Section}
\begin{SeeAlso}\relax
\code{\LinkA{bandSparse}{bandSparse}} for the \emph{construction} of a banded
sparse matrix directly from its non-zero diagonals.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## 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

\end{ExampleCode}
\end{Examples}

