title: Updating Issue Using Function in R
body: <p>I am having an updating issue with my code and was hoping that somebody more versed with "functions" in R will be able to figure it out. As you see here the variable "R" changes, and when calling upon that variable in FuncTest the only the R value of 2.05 is used. Which is why the first 3 values produce the desired output then it all goes down hill from there. How would this be amended?    </p>
  
  <pre><code> R &lt;- t(c(2.05, 2.05, 2.05, 2.55, 2.55, 2.55, 2.95, 2.95, 2.95))
   P &lt;- 6447.88
  
  EnvTest &lt;- new.env()
  EnvTest$Orig &lt;- 548453.5
  
  FuncTest &lt;- function(pp){
    EnvTest$Orig &lt;- EnvTest$Orig-(P-EnvTest$Orig*R[pp]/1200)
    return(EnvTest$Orig)
  }
  Test&lt;- rbind(EnvTest$Orig,
                  do.call(rbind,lapply(1:9, FuncTest)))
  x &lt;- t(Test)
  x
  </code></pre>
  
  <p>This gives the output: </p>
  
  <pre><code>    [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]     [,9]    [,10]
  [1,] 548453.5 542942.6 537422.2 531892.4 526574.8 521245.9 515905.7 510726.1 505533.7 500328.6
  </code></pre>
  
  <p>The desired output is: </p>
  
  <pre><code>    [,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]   [,8]   [,9]  [,10]
  [1,] 548453 542942 537422 532116 526799 521470 516304 511126 505934 500941
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I am trying to use the updated value of EnvTest$Orig, to calculate the EnvTest$Orig for 10 different values. To do that I am using the variable "R". The output of "x" correctly produces the first three results. But as you see the varible R changes after the first three inputs from 2.05 to 2.55. My function is not properly using the new "R" value and continues to use 2.05 instead of 2.55. This is shown in the code below, which is attempting to calculate the 4th column in the desired output. It is clear that "Proof2" does the properly while "Proof" demonstartes that my function only uses the first instance of the variable "R".  </p>
  
  <pre><code>Proof &lt;- 537422-(P-(537422*2.05/1200))
  Proof
  </code></pre>
  
  <p>Which gives an answer of 531892.2 but it should be 532116, as shown below. </p>
  
  <pre><code> Proof2 &lt;- 537422-(P-(537422*2.55/1200))
   Proof2
  </code></pre>
  
  <p><strong>Update Round 2</strong></p>
  
  <p>There was nothing wrong with the function, and instead with the variable "R" and this is why I could not get the desired output. Big thanks to RHertel. </p>