Another alternative to the R base that uses cumprod
to generate internal terms is
sum(cumprod(c(1, seq(2, 10, 2)) / c(1, seq(3, 11, 2))))
[1] 3.4329
Here it c(1, seq(2, 10, 2)) / c(1, seq(3, 11, 2))
generates the sequence 1, 2/3, 4/5, 6/7, 8/9, 10/11 and cumprod
takes the cumulative product. This result is cumulative with sum
. The result obtained is identical to that returned in the accepted answer.
source
share