\HeaderA{bdiag}{Construct a Block Diagonal Matrix}{bdiag}
\keyword{array}{bdiag}
\begin{Description}\relax
Build a block diagonal matrix given several building block matrices.
\end{Description}
\begin{Usage}
\begin{verbatim}
bdiag(...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{...}] individual matrices or a \code{\LinkA{list}{list}} of matrices.
\end{ldescription}
\end{Arguments}
\begin{Value}
A \emph{sparse} matrix inheriting from class
\code{\LinkA{CsparseMatrix}{CsparseMatrix.Rdash.class}}
obtained by combining the arguments into a block diagonal matrix.
\end{Value}
\begin{Author}\relax
Martin Maechler, built on a version posted by Berton Gunter to
R-help; earlier versions have been posted by other authors, notably
Scott Chasalow to S-news.  Doug Bates's faster implementation builds
on \code{\LinkA{TsparseMatrix}{TsparseMatrix.Rdash.class}} objects.
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{Diagonal}{Diagonal}} for constructing matrices of
class \code{\LinkA{diagonalMatrix}{diagonalMatrix.Rdash.class}}, or \code{\LinkA{kronecker}{kronecker}}
which also works for \code{"Matrix"} inheriting matrices.

\code{\LinkA{bandSparse}{bandSparse}} constructs a \emph{banded} sparse matrix from
its non-zero sub-/super - diagonals.

Note that other CRAN \R{} packages have own versions of \code{bdiag()}
which return traditional matrices.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
bdiag(matrix(1:4, 2), diag(3))
## combine "Matrix" class and traditional matrices:
bdiag(Diagonal(2), matrix(1:3, 3,4), diag(3:2))

mlist <- list(1, 2:3, diag(x=5:3), 27, cbind(1,3:6), 100:101)
bdiag(mlist)

stopifnot(identical(bdiag(mlist), 
                    bdiag(lapply(mlist, as.matrix))))
\end{ExampleCode}
\end{Examples}

