[R] colSum() in Matrix objects

Jose Quesada quesada at gmail.com
Mon Apr 16 20:41:46 CEST 2007


I'd like to simply add column-wise using Matrix objects (Csparse).
It looks like one can apply mosty any base function to these objects  
(i.e., apply, colSums), but there is a nasty conversion to traditional  
matrix objects if one does that.
Is there any workaround? I can see colSum listed in the help for Class  
'CsparseMatrix' , but I wonder whether I'm using the default colSums() or  
the one specific to CsparseMatrix...

(z = Matrix(c(0,1,0,0), 10,10))
zr = rowSums(z)
class(zr) # numeric; I'd like it to be a CSparseMatrix object

Thanks a lot in advance,

Jose Quesada, PhD.

More information about the R-help mailing list