[R] spare matrix replacing values efficiently

2010-08-22 Thread david h shanabrook
I am working with a large sparse matrix trying replace all 1 values with 0. The normal method doesn't work. Here is a small example: x - Matrix(0,nrow=10,ncol=10,sparse=TRUE) x[,1] - 1:2 x 10 x 10 sparse Matrix of class dgCMatrix [1,] 1 . . . . . . . . . [2,] 2 . . . . . . . . . [3,] 1 . .

[R] incrementing matrix elements more efficiently

2010-08-14 Thread david h shanabrook
I need to increment cells of a matrix (collusionM). The indexes to increment are in an index (matchIndex). This is some of the code for (j in 1:(rows-1)) matchIndex[[j]] - which(mx[j]==mx) for (j in 1:(rows-1)) collisionM[j,matchIndex[[j]]] - collisionM[j,matchIndex[[j]]] + 1

[R] incrementing matrix elements more efficiently

2010-08-14 Thread david h shanabrook
I need to increment cells of a matrix (collusionM). The indexes to increment are in an index (matchIndex). This is sample code library(seqinr) library(Matrix) x - abcabcabc mx - s2c(x) collisionM - Matrix(0,nrow=10, ncol=10, sparse=TRUE) matchIndex - list() rows -

[R] subset of string by index

2010-08-08 Thread david h shanabrook
How can I get a substring based on the index into the string? strM - c(abcde, cdefg) ind - c(1,3,5) I want to use ind to index into the strings so the result is: strMind - c(ace, ceg) __ R-help@r-project.org mailing list

[R] subset of string by index

2010-08-08 Thread david h shanabrook
How can I get a substring based on the index into the string? strM - c(abcde, cdefg) ind - c(1,3,5) I want to use ind to index into the strings so the result is: strMind - c(ace, ceg) __ R-help@r-project.org mailing list

[R] efficient matrix element comparison

2010-08-08 Thread david h shanabrook
It is a simple problem in that I simply want to convert the For loop to a more efficient method. It simply loops through a large vector checking if the numeric element is not equal to the index of that element. The following example demonstrates a simplified example: rows - 10 collusionM -