Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives?

2012-06-26 Thread Søren Højsgaard
Dear Duncan Thanks for your suggestion, but I really need sparse matrices: I have implemented various graph algorithms based on adjacency matrices. For large graphs, storing all the 0's in an adjacency matrices become uneconomical, and therefore I thought I would use sparse matrices but the

Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives?

2012-06-26 Thread Søren Højsgaard
Duncan, I should probably add that I am aware that my code is not the solution and also that the relative gain of my code probably decreases with the problem size until eventually it will perform worse that [i,j] (because of copying I suppose). So my point is just: It would just be nice if

Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives?

2012-06-25 Thread Duncan Murdoch
On 12-06-24 4:50 PM, Søren Højsgaard wrote: Dear all, Indexing matrices from the Matrix package with [i,j] seems to be very slow. For example: library(rbenchmark) library(Matrix) mm- matrix(c(1,0,0,0,0,0,0,0), nr=20, nc=20) MM- as(mm, Matrix) lookup- function(mat){ for (i in

[R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there faster alternatives?

2012-06-24 Thread Søren Højsgaard
Dear all, Indexing matrices from the Matrix package with [i,j] seems to be very slow. For example: library(rbenchmark) library(Matrix) mm - matrix(c(1,0,0,0,0,0,0,0), nr=20, nc=20) MM - as(mm, Matrix) lookup - function(mat){ for (i in 1:nrow(mat)){ for (j in 1:ncol(mat)){