(M <- bdiag(Diagonal(2), matrix(1:3, 3,4), diag(3:2)))
colSums(M)
d <- Diagonal(10, c(0,0,10,0,2,rep(0,5)))
MM <- kronecker(d, M)
dim(MM) # 40 140
cm <- colSums(MM)
(scm <- colSums(MM, sparseResult = TRUE))
stopifnot(is(scm, "sparseVector"),
identical(cm, as.numeric(scm)))
rowSums(MM, sparseResult = TRUE) # 8 of 40 are not zero
if(FALSE) ## FIXME! -- requires <sparseVec> / <scalar>
rowMeans(MM, sparseResult = TRUE)
Run the code above in your browser using DataLab