[R] Efficient matrix slices

Gabriel Valiente valiente at lsi.upc.edu
Sun Jul 8 19:30:40 CEST 2007


Indexing matrices by subsets of rows and columns is quite convenient,  
but it seems to take time linear in the size of the matrix (even for  
a small slice of the matrix):

 > dim(y)
[1]  732 1332
 > length(which(a[1,]==1))
[1] 4
 > length(which(b[1,]==1))
[1] 12
 > proc.time(y[which(a[1,]==1),which(b[1,]==1)])
[1]  32.596   1.809 510.928   0.000   0.000
 > proc.time(sum(y))
[1]  33.082   1.914 547.469   0.000   0.000

Does anybody know how matrix slices are actually implemented in R?  
Thanks a lot,

Gabriel



More information about the R-help mailing list