There is a fantastically useful math operator called the Kronecker product :
m1 <- matrix(1:4,nrow=2,byrow=TRUE) m2 <- matrix(1,nrow=2,ncol=2) kronecker(m1,m2)
The Matrix package has methods for Kronecker products with sparse matrices ( ?"kronecker-methods" ), so you can easily create huge sparse matrix matrices, while you can find a way to express the template in terms of Kronecker products.
source share