[R] Geometric progression

Andre Nathan andre at digirati.com.br
Mon Feb 25 03:26:05 CET 2008


Hi

I'm pretty sure there's some built-in function to do the equivalent of
this, but I couldn't find one anywhere:

gp <- function(init, mult, n)
{ 
  if (n == 1)
    init
  else
    pg(c(init, init[length(init)] * mult), mult, n-1)
}

> gp(1, 2, 10)
 [1]    1    2    4    8   16   32   64  128  256  512 1024

Any pointers?

Thanks,
Andre



More information about the R-help mailing list