bdiag {spam} | R Documentation |
Binds Arrays Corner-to-Corner
Description
Creates a sparse block-diagonal matrix.
Usage
bdiag.spam(...)
Arguments
... |
Arrays to be binded together |
Details
This is a small helper function to create block diagonal sparse matrices. In the two matrix case,
bdiag.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 bdiag
from the package
Matrix
. It is also similar to the function adiag
from the package
magic
. However, here no padding is done and all the dimnames are
stripped.
Value
Returns a spam
matrix as described above.
Author(s)
Reinhard Furrer
See Also
Examples
A <- diag.spam(2, 4) # 2*I4
B <- matrix(1,3,3)
AB <- bdiag.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:
bdiag.spam(1,2:5,6)
[Package spam version 2.10-0 Index]