Hi:
What about
colSums(mymat != 0)
?
# Example:
x <- matrix(sample(c(-1, 0, 1, 2), 100, replace = TRUE, prob = c(0.1,
0.8, 0.07, 0.03)),
nrow = 25)
which(x != 0) # 17 nonzero elements in this matrix
[1] 9 17 27 32 36 41 44 45 49 50 62 67 68 72 76 78 82
colSums(x != 0)
[1] 2 8 4
Hi R users,
I want to know whether there is a fast method to compute the nonzeroes for
each column of dgCMatrix.
For summation or average I can use colSums or colMeans. To count the
non-zeroes I write a function
colCounts <- function(Mat) {
M1 <- apply(Mat, MARGIN=2, FUN=nnzero)
}
But it se
2 matches
Mail list logo