title: How do I delete all rows based on a loop in R
body: <p>I am writing a for loop to delete rows in which all of the values between rows 5 and 8 is 'NA'. However, it only deletes SOME of the rows. When I do a while loop, it deletes all of the rows, but I have to manually end it (i.e. it is an infinite loop...I also have no idea why)</p>
  
  <p>The for/if loop: </p>
  
  <pre><code>     for(i in 1:nrow(df)){
  if(is.na(df[i,5]) &amp;&amp; is.na(df[i,6]) &amp;&amp; 
      is.na(df[i,7]) &amp;&amp; is.na(df[i,8])){
    df&lt;- df[-i,]
  }
    }
  </code></pre>
  
  <p>while loop (but it is infinite):</p>
  
  <pre><code> for(i in 1:nrow(df)){
      while(is.na(df[i,5]) &amp;&amp; is.na(df[i,6]) &amp;&amp; 
          is.na(df[i,7]) &amp;&amp; is.na(df[i,8])){
        df&lt;- df[-i,]
      }
        }
  </code></pre>
  
  <p>Can someone help? Thanks! </p>