[R] Matrix package: band matrix

Ken Knoblauch ken.knoblauch at inserm.fr
Fri Feb 20 15:11:55 CET 2009


Thomas Lumley <tlumley <at> u.washington.edu> writes:

> I want to construct a symmetric band matrix in the Matrix 
> package from a matrix where the first column
> contains data for the main diagonal, the second column 
> has data for the first subdiagonal/superdiagonal
> and so on.
> 
> Since the Matrix will be 10^5 x 10^5 or so, with perhaps 
> 10-20 non-zero elements above the diagonal per row, I
> can't do it by constructing a full matrix and then using the band() 
> function to subset it to a band matrix.
> 
> Any suggestions?
> 
>        -thomas
> 
> Thomas Lumley			Assoc. Professor, Biostatistics
> tlumley <at> u.washington.edu	University of Washington, Seattle
> 
I'm not expert but just looking at the package,
perhaps the spMatrix function (constructor) would do it.

spMatrix(5, 5, c(2:5, 1:5, 1:4), c(1:4, 1:5, 2:5), rnorm(13))
5 x 5 sparse Matrix of class "dgTMatrix"
                                                             
[1,] -1.7109379 -0.5576860  .            .          .        
[2,] -0.3219899 -0.9294558  0.001323253  .          .        
[3,]  .          0.4099070  0.646068453  0.5388224  .        
[4,]  .          .         -1.007848357 -0.1117796 -0.5555834
[5,]  .          .          .           -0.6816979 -0.6052127

Ken

-- 
Ken Knoblauch
Inserm U846
Stem-cell and Brain Research Institute
Department of Integrative Neurosciences
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html



More information about the R-help mailing list