Skip to content
Prev 41091 / 63424 Next

matrix bands

Thanks for the suggestion, Martin!

I looked at both Matrix::band and Matrix::bandSparse. Maybe I 
misunderstand the help pages and the examples, but from what I can see 
neither of them provides the functionality I was looking for.

For the getter version of the function I was looking for, I can't use 
Matrix::band (by extracting the non-zero elements) because this would 
require the assumption that the specified band is entirely non-zero, e.g.:

band3 <- function(x,n){
   x <- Matrix::band(x,n,n)
   x[x!=0] ## works for a dense matrix, but not if band n has zeroes
}

As for the setter version of the function I was looking for, it should 
set the values of a specified band in an existing matrix to be the 
vector of values provided. As far as I understand, Matrix::bandSparse 
constructs a matrix rather than modifying the values of an existing matrix.

The functions included in my last post filled this gap. If Matrix::band 
and Matrix::bandSparse can set/get bands in this way, I would like to 
see how this can be done. If not, then perhaps they could be extended to 
achieve this functionality.
On 2011-08-26 14:08, Martin Maechler wrote: