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,]
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 <-
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
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
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
https://stat.ethz.c
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
https://stat.ethz.c
6 matches
Mail list logo