title: for looping through rows of a tibble runs properly but produces values for i
body: <p>I am trying to write a for loop in R that produces a number range based a value in col 3 and checks if the value in col 2 falls within that range. For positive hits I would like it print out the entire row</p>
  
  <p>I think my current for loop is running properly (no positive results) but it produces weird values in my workspace</p>
  
  <p>here is my current for loop:</p>
  
  <pre><code>for(i in 1:nrow(df)) {
      low &lt;- (df[[i, 3]] - 11)
      high &lt;- (df[[i, 3]] + 11)
  
      if(df[[i, 2]] &lt; high &amp;&amp; df[[i, 2]] &gt; low) {
      print(df[[i,]])
     }
  }
  </code></pre>
  
  <p>a simplified data frame of the data looks like this</p>
  
  <pre><code>df = data.frame(Gene = c("ABCA7", "AP1B1", "CENPE", "COPA", "COPA", "COPA", "ZNF592"), 
       Starting.Position = c(273, 188, 1541, 1207, 1207, 545, 1052), 
       Mutation = c(1293, 230, 2562, 792,792,792, 186))
  </code></pre>
  
  <p>When I run this loop nothing is outputted--which i think is accurate---but three objects are created in my workspace: "high = 197, low = 175, and i = 6L". Not sure why this is happening and it is bothering me, would like to know why and I am unable to find any errors in my code. These values are the loop running on the last row of the data frame. </p>
  
  <p>Thank you, I am relatively new to using R.</p>