Skip to content
Prev 69531 / 398525 Next

simplify loop

On Wed, 11 May 2005 13:05:58 -0400 Omar Lakkis wrote:

            
Yes, as the loop above as only one iteration, you can easily do it as:
  n <- length(settle)
  settle[n-1] <- settle[n]/(1 + settle.pct[n])

What you probably really meant, can also be simply done without a for
loop. You need a vector settle.pct and a scalar starting value (not a
full vector) settle. So in the following settle is assumed to be only
settle[n]:

  settle/c(rev(cumprod(1 + rev(settle.pct)))[-1], 1)

If settle.pct should in fact also be only be constant, this can of
course be further simplified.
Z