The seq function in R will give me a sequence from x to y with a constant step m :
seq(x, y, m)
eg. 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 , so something like "seq(x, y, c(m1, m2))" will give me c(x, x + m1, (x + m1) + m2, (x + m1 + m2) + m1, ..., y) , each time adding one of the steps (does not necessarily reach y , of course, as in seq )?
Example: x = 1; y = 19; m1 = 2; m2 = 4 x = 1; y = 19; m1 = 2; m2 = 4 x = 1; y = 19; m1 = 2; m2 = 4 and I get c(1,3,7,9,13,15,19) .
r seq
Giora simchoni
source share