title: how to avoid this loop in R (rapply ? lapply ?)
body: <p>I'm trying to replace this loop by a symple command without any succes (lapply ? rapply ? mapply ?). Maybe it's a rare case in R that loops are really needed ?</p>
  
  <pre><code>n &lt;- 10
  x &lt;- vector(mode="numeric", length=n)
  
  for(i in 2:n) {
      x[i] &lt;- x[i-1]+runif(1)
  }
  </code></pre>
  
  <p>my question was badly formulated. The responses helped me understand that what I actually need is to access the values ​​of a vector into a function. With a loop that is simple for any function "f" we can be calculated:</p>
  
  <pre><code>x &lt;- c(1,2,3,4)
  for(i in 2:4) {
      x[i] &lt;- f(x[i-1])
  }
  </code></pre>
  
  <p>Maybe the only way is global variables ?</p>