I have a lot of rows and columns in a very large matrix (184 x 4000, type double), and I want to remove all 0\'s. The values in the matrix are usually greater than 0 but the
You can drop rows which only contain 0s like this (and you could replace 0 with any other number if you wanted to drop rows with only that number):
x <- x[rowSums(x == 0) != ncol(x),]
Explanation:
x == 0
creates a matrix of logical values (TRUE/FALSE) and
rowSums(x == 0)
sums them up (TRUE == 1, FALSE == 0). ncol(x)
).