Count number of zeros per row, and remove rows with more than n zeros

It’s not only possible, but very easy:

DF[rowSums(DF == 0) <= 4, ]

You could also use apply:

DF[apply(DF == 0, 1, sum) <= 4, ]

Leave a Comment