Dear Khazaei,

What about this?

w <- 1:10
N <- length(w)
a <- 1
b <- 1
w[2:(N-1)] <- w[2:(N-1)]*(a/(b+(2:(N-1))))
> w
 [1]  1.0000000  0.6666667  0.7500000  0.8000000  0.8333333  0.8571429
 [7]  0.8750000  0.8888889  0.9000000 10.0000000
Note that here I assumed "a" and "b" were constants 1 and 1, respectively.
It is no problem to substitute vectors in for them.  As long as "a" and "b"
are the same length or a multiple of k...N-1, you can substitute them
directly in the formula above and R will just keep using them until it is
done.

Hope that helps,


Josh


On Fri, Feb 26, 2010 at 7:23 AM, <khaz...@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@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to