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?
P.s. please ignore (or correct) the tags of this post. I just was’t sure which tags would be most appropriate for this problem.
>Solution :
any(apply(m[, 1:10], MARGIN = 1, function(x) all(x != 0))) should be pretty quick.