How to erase rows in a data frame R <p>I have a data frame that look like this:</p> <pre><code>Quality Data Name 1 667 green 3 647 white 1 626 Blue 2 345 yellow 1 550 Blue 5 730 green </code></pre> <p>i want a code that goes through a for loop and takes the one less the 600 and greater than 700 and delete the row &amp;&amp; all the ones with the same name and saves the ones that were deleted in another data frame<br> example </p> <pre><code> for i in nrow(df){ if (df$Data[i]&lt;=600 || df$Data[i]&gt;=700){ Subset_by_name=subset(df,df$Name==df$Name[i]) (saves bad samples) (delete from data) Subset_by_name=data.frame(Subset_by_name) bad_sample=rbind(Subset_by_name) (saves all the bad data in a data frame) } } </code></pre> <p>result<br> bad_sample</p> <pre><code>Quality Data Name 1 667 green 1 626 Blue 2 345 yellow 1 550 Blue 5 730 green </code></pre> <p>data</p> <pre><code>Quality Data Name 3 647 white </code></pre> <p>help please????</p>