Skip to content
Prev 332981 / 398503 Next

repeating values in an index two by two

Or you can use the integer divide and remainder operators:
   > n <- 30
   > x <- seq(0, len=n)
   > + (x %% 2) + (x %/% 4)*2 + 1 # period 2 oscillator + jump by 2 every fourth
    [1]  1  2  1  2  3  4  3  4  5  6  5  6  7  8  7
   [16]  8  9 10  9 10 11 12 11 12 13 14 13 14 15 16

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com