bdiag                 package:Matrix                 R Documentation

_C_o_n_s_t_r_u_c_t _a _B_l_o_c_k _D_i_a_g_o_n_a_l _M_a_t_r_i_x

_D_e_s_c_r_i_p_t_i_o_n:

     Build a block diagonal matrix given several building block
     matrices.

_U_s_a_g_e:

     bdiag(...)

_A_r_g_u_m_e_n_t_s:

     ...: individual matrices or a 'list' of matrices.

_V_a_l_u_e:

     A _sparse_ matrix inheriting from class 'CsparseMatrix' obtained
     by combining the arguments into a block diagonal matrix.

_A_u_t_h_o_r(_s):

     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 'TsparseMatrix' objects.

_S_e_e _A_l_s_o:

     'Diagonal' for constructing matrices of class 'diagonalMatrix', or
     'kronecker' which also works for '"Matrix"' inheriting matrices.

     'bandSparse' constructs a _banded_ sparse matrix from its non-zero
     sub-/super - diagonals.

     Note that other CRAN R packages have own versions of 'bdiag()'
     which return traditional matrices.

_E_x_a_m_p_l_e_s:

     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))))

