[R] Alternating numbers in rep()

David Afshartous dafshartous at med.miami.edu
Thu Jan 24 21:03:22 CET 2008


All,

I'm trying to obtain a one-liner to generate a certain sequence of
alternatign numbers.

Consider:
> unlist(rep(list(c(1,2), c(3,4)), each = 6))
 [1] 1 2 1 2 1 2 1 2 1 2 1 2 3 4 3 4 3 4 3 4 3 4 3 4

I'd like the result to be as above but continue until 38.  Of course, I
could hardcode this going up to c(37,38), but is there a more elegant way?


Thanks!
David



More information about the R-help mailing list