I have a large sparse matrix ("dgCMatrix", dimension 5e+5 x 1e+6). I need to count for each column how many non-zero values there are and make a list of column names with only 1 non-zero entry.
My code works for small matrices, but becomes too computationally intensive for the actual matrix I need to work on.
library(Matrix)
set.seed(0)
mat <- Matrix(matrix(rbinom(200, 1, 0.10), ncol = 20))
colnames(mat) <- letters[1:20]
entries <- colnames(mat[, nrow(mat) - colSums(mat == 0) == 1])
Any suggestion is very welcome!