Select rows from data frame which have at least three negative values? <p>How to filter rows which have atleast 3 negative values?</p> <pre><code>df1 &lt;- Name flex flex2 flex3 flex4 Set1 -1.19045139 -1.25005615 -1.053900875 -1.15142391 Set2 -2.22129212 1.54901305 0.003462145 1.06170243 Set3 -2.08952248 -1.95241584 -1.206060696 -1.65450460 Set4 -1.20091116 0.50700470 -0.098793884 1.50406054 Set5 -1.11771409 0.01175919 -3.056481406 -1.09328262 Set7 -9.01648659 0.07707638 0.198978232 1.18125182 </code></pre> <p>expected output</p> <pre><code>df2 &lt;- Name flex flex2 flex3 flex4 Set1 -1.19045139 -1.25005615 -1.053900875 -1.15142391 Set3 -2.08952248 -1.95241584 -1.206060696 -1.65450460 Set5 -1.11771409 0.01175919 -3.056481406 -1.09328262 </code></pre> <p>i tried the code given below, but it doesn't work</p> <pre><code>Index= as.vector(which(apply(df1,1,function(x){sum(x &lt; -1)/length(x)})&gt;=0.75)) df1[Index,] </code></pre>