title: unfold function in R?
body: <p>R has fold function <code>Reduce</code>. is there a corresponding unfold function? say, given a starting value and apply a function recursively to get an array? The for loop will do the job, just wondering if there is more R-like way for this. thanks,</p>
  
  <p>An example, the code below plot lorenz attractor in 8 lines (mimic <a href="http://fsharpnews.blogspot.com/2010/07/lorenz-attractor.html" rel="nofollow">F# Lorenz Attractor in 35 lines</a>. But the for loop looks ugly. Can we do better?</p>
  
  <pre><code>s &lt;- 10; b &lt;- 8/3; p &lt;- 28
  dt &lt;- 0.003; n&lt;-2000
  x &lt;- matrix(0,n,3); x[1,] &lt;- c(10,0,20)
  for (i in 2:n){
      x[i,] &lt;- x[i-1,] + c(s * (x[i-1,2] - x[i-1,1]),x[i-1,1] * (p - x[i-1,3]) - x[i-1,2],x[i-1,1] * x[i-1,2] - b * x[i-1,3]) * dt
  }
  library(rgl)
  plot3d(x,type= 'l',col = 'red')
  </code></pre>