| adiag {spam} | R Documentation |
Creates a sparse block-diagonal matrix.
adiag.spam(...)
... |
Arrays to be binded together |
This is a small helper function to create block diagonal sparse matrices. In the two matrix case,
adiag.spam(A,B), this is equivalent to a complicated rbind(cbind(A, null), cbind(B, t(null))),
where null is a null matrix of appropriate dimension.
It is recursively defined.
The arrays are coerced to sparse matrices first.
This function is similar to the function adiag from the package magic.
However, here no padding is done and all the dimnames are stripped.
Returns a spam matrix as described above.
Reinhard Furrer
A <- diag.spam(2, 4) # 2*I4
B <- matrix(1,3,3)
AB <- adiag.spam(A,B)
# equivalent to:
ABalt <- rbind(cbind( A, matrix(0,nrow(A),ncol(B))),
cbind( matrix(0,nrow(B),ncol(A)), B))
norm(AB-ABalt)
# Matrices do not need to be square:
adiag.spam(1,2:5,6)