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]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.