title: Loop not changing values in dataframe - R
body: <p>I have a loop that works fine, but the output is only returned in console, dataframe remains unmodified.</p>
  
  <ul>
  <li>a the end of the loop the head(data) is returned in the console, producing the expected values in the expected column</li>
  <li>however, this is not changed in the original dataframe, where I want the values to appear (printing the head(data) now gives me the original values, not the new ones created by the loop)</li>
  </ul>
  
  <p>Sample code:</p>
  
  <pre><code>df &lt;- cbind(x,y)
  myfun &lt;- function(z){
      counter &lt;- 0
      for (i in 1:z) {
      counter &lt;- 1 + counter
          for (j in 1:5) {
          counter &lt;- 1 + counter
              if (condition_a){
                  df[counter,2] &lt;- 0
              }
              if (condition_b){
                  df[counter,2] &lt;- 1
              }
          }
      }
      return(head(df))
      newdf &lt;- df[,2]
  }
  </code></pre>
  
  <p>What am I missing? </p>
  
  <p>The values are of class int, should this matter?</p>