[R] how to get empty sequence for certain bounds

Tamas K Papp tpapp at Princeton.EDU
Wed Nov 15 17:35:44 CET 2006


I have encountered this problem quite a few times and thought I would

Let's say that I have two endpoints, a and b, which are integers.  If
a <= b, I would like to get a:b, but if a > b, then numeric(0), for

myseq(3,5) => 3:5
myseq(3,3) => 3
myseq(3,2) => numeric(0)

The operator : just gives decreasing sequences in the latter case, and
I could not coax seq into doing this either (of course the
documentation is correct, it never claims that I could).  Should I
just write my own function, or is there a standard R way to do this?



More information about the R-help mailing list