Function to transform a dataframe is not working properly
<p>I have a dataframe that looks like this:</p>

<pre><code> x &lt;- c(1,2,3)
 y &lt;- c(4,5,5)

 df &lt;- data.frame(x,y)
</code></pre>

<p>Now I would like to run my dataframe through a function to deal with the 5 values.</p>

<p>So like</p>

<pre><code>getRidOdNAs &lt;- function(df){

  for (i in 1:nrow(df)){

    if(df$y[i] == 5){

       df$y[i] &lt;- 0

    }
  }
 return(df)
 }
</code></pre>

<p>Now this works. But when I call my dataframe df afterwards I get again:</p>

<pre><code>&gt; df
  x y
  1 1 4
  2 2 5
  3 3 5
</code></pre>

<p>Any thoughts what I should do so get back the changed dataframe?</p>