[R] question to make a vector without loop
Uwe Ligges
ligges at statistik.tu-dortmund.de
Fri Feb 26 16:45:21 CET 2010
On 26.02.2010 16:23, 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?
Sure:
wMake <- function(w, a, b, n){
w * (a^(0:(n-1))) / cumprod(c(1, (b+1):(b+n-1)))
}
wMake(w=1, a=2, b=3, n=10)
Uwe Ligges
>
> 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