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

