title: Update data frame via function doesn't work
body: <p>I ran into a little problem using R…</p>
  
  <p>In the following data frame</p>
  
  <pre><code>test &lt;- data.frame(v1=c(rep(1,3),rep(2,3)),v2=0) 
  </code></pre>
  
  <p>I want to change values for v2 in the rows where v1 is 1.</p>
  
  <pre><code>test[test$v1==1,"v2"] &lt;- 10
  </code></pre>
  
  <p>works just fine.</p>
  
  <pre><code>test
    v1 v2
  1  1 10
  2  1 10
  3  1 10
  4  2  0
  5  2  0
  6  2  0
  </code></pre>
  
  <p>However, I need to do that in a function.</p>
  
  <pre><code>test &lt;- data.frame(v1=c(rep(1,3),rep(2,3)),v2=0)
  
  test.fun &lt;- function (x) {
      test[test$v1==x,"v2"] &lt;- 10
      print(test)
  }
  </code></pre>
  
  <p>Calling the function seems to work.</p>
  
  <pre><code>test.fun(1)
    v1 v2
  1  1 10
  2  1 10
  3  1 10
  4  2  0
  5  2  0
  6  2  0
  </code></pre>
  
  <p>However, when I now look at test:</p>
  
  <pre><code>test
    v1 v2
  1  1  0
  2  1  0
  3  1  0
  4  2  0
  5  2  0
  6  2  0
  </code></pre>
  
  <p>it didn’t work.
  Is there a command that tells R to really update the data frame in the function?
  Thanks a lot for any help!</p>