Suppose we have a 300 x 1000 matrix. If there exists any row of this matrix such that the first 10 elements of the row are non-zero, then a condition is satisfied. What is the quickest way to write this code instead of doing it using for loops?
CodePudding user response:
any(apply(m[, 1:10], MARGIN = 1, function(x) all(x != 0)))
should be pretty quick.