A general facility for this is Reduce: f <- function(w, k, a = 2, b = 1) w*a / (b+k) c(7, Reduce(f, 2:9, 7, accumulate = TRUE))
the result of which is: c(7, Reduce(f, 2:9, 7, accumulate = TRUE)) [1] 7.0000000000 7.0000000000 4.6666666667 2.3333333333 0.9333333333 0.3111111111 0.0888888889 0.0222222222 0.0049382716 0.0009876543 On Fri, Feb 26, 2010 at 10:23 AM, <[email protected]> wrote: > Hello all, > > I want to define a vector like w[k+1]=w[k]*a/(b+k) for k=1,...,N-1 without > use loop. Is it posible to do in R? > > Regards > > khazaei > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

