Displaying 2 results from an estimated 2 matches for "collusionm".
2010 Aug 09
2
efficient matrix element comparison
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 <- Matrix(0,10,10,sparse=TRUE)
> matchM <- matrix(c(1,2,3,4,4,6,7,9,9,10))
>
> for (j in 1:rows) if (j != matchM[j]) collusionM[j,matchM[j]] <- collusionM[j,matchM[j]]+1
> collusionM
10 x 10 sparse Matrix of class "dgCMatrix"
[1,] . . . . ....
2010 Aug 14
1
incrementing matrix elements more efficiently
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
I could put them in the same loop but this is slower. The...