I have a vector a and want to multiply each element recursively with b, without using a loop.
a <- rep(0, 10)
a[1] <- 1
b <
The exponent function ^ is vectorized, so quite simply:
2^(0:9)
# [1] 1 2 4 8 16 32 64 128 256 512
which you might also want to write
2^seq(from=0, to=9)
For long vectors, I am pretty sure @JoshuaUlrich's method will be much faster, but this one is certainly very compact. You also said you were not particularly concerned about speed.