[R] question to make a vector without loop
Linlin Yan
yanlinlin82 at gmail.com
Fri Feb 26 17:10:05 CET 2010
For general purpose of recursion formula, you could do it like this:
> make.vector <- function(w, n, a, b) c(w, sapply(1:(n-1), function(x) w <<- w * a / (b + x)))
> make.vector(w = 1, n = 4, a = 24, b = 1)
[1] 1 12 96 576
On Fri, Feb 26, 2010 at 11:23 PM, <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