[R] question to make a vector without loop
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Feb 26 17:30:45 CET 2010
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, <khazaei at ceremade.dauphine.fr> 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
>
> ______________________________________________
> R-help at r-project.org 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.
>
More information about the R-help
mailing list