Btw, forgot to mention I am using the standard Matrix package and I am
running version 2.10.1 of R.

On Mon, Dec 6, 2010 at 11:04 AM, scott white <distributedintel@gmail.com>wrote:

> I have a very sparse square matrix which is < 20K rows & columns and I am
> trying to row standardize the matrix for the rows that have non-missing
> value as follows:
>
> row_sums <- rowSums(M,na.rm=TRUE)
> nonzero_idxs <- which(row_sums>0)
> nonzero_M <- M[nonzero_idxs,]/row_sums[nonzero_idxs]
> M[nonzero_idxs,] <- nonzero_M
>
> Each line completes well under a second except the last line which takes
> well over 10 seconds which is simply assigning the sub-matrix of rows that
> have non-missing values to the complete matrix. I am curious to know why it
> is so slow and how to speed it up. Should I be doing this differently or try
> a different sparse matrix library?
>
> Any feedback is appreciated.
>
> thanks,
> Scott
>
>

	[[alternative HTML version deleted]]

