title: How to write a for loop that deletes row data in R
body: <p>I have a large csv file which I imported into R as a data frame. To avoid manually editing my CSV file, I am attempting to complete it in R using a loop. The code is as follows:</p>
  <pre><code>  if(Practice$zt[x] &gt;= 0.0 &amp;  Practice$zt[x] &lt;= 2.5) {
      
       print(Practice$zt[x])
     
    }
    if(Practice$zt[x] &gt;= 12.0 &amp; Practice$zt[x] &lt;= 14.5) {
      
      print(Practice$zt[x])
    } 
    
  }
  </code></pre>
  <p>Essentially, I want my code to go through the dataframe starting at row 1 and check if the zt column is either between 0-2 or 12-14. Any number not in these ranges will delete the whole row, but I can't get my loop to correctly run through the code. I keep receiving this error:</p>
  <pre><code>In if (Practice$zt[x] &gt;= 0 &amp; Practice$zt[x] &lt;= 2.5) { :
    the condition has length &gt; 1 and only the first element will be used
  </code></pre>
  <p>Any suggestions? Thanks in advance.</p>