The seq
function in R would give me a sequence from x
to y
with a constant step m
:
seq(x, y, m)
E.g. seq(1,9,2) = c(1,3,5,7,9)
.
What would be the most elegant way to get a sequence from x
to y
with alternating steps m1
and m2
, such that something like "seq(x, y, c(m1, m2))"
would give me c(x, x + m1, (x + m1) + m2, (x + m1 + m2) + m1, ..., y)
, each time adding one of the steps (not necessarily reaching up to y
, of course, as in seq
)?
Example: x = 1; y = 19; m1 = 2; m2 = 4
and I get c(1,3,7,9,13,15,19)
.
c(1, 1+2, 3+4, 7+2, 9+4, 13+2, 15+4)
. Alternating the step between 2 and 4. – Toothpick