In the example, you can find the formula for x [i] and see if it can be vectorized. In this case, I think cumprod might work.
x <- c(1, cumprod(2*y)[1:99])
In some cases, you can also use the filter command in convolution or recursion mode. See ?filter
However, if you cannot work out a formula for the nth value that matches one of the forms above, you can try using a package, such as inline or Rcpp , to write this in a loop in C / C ++.
source share