[R] seq in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Jun 24 19:01:30 CEST 2005


Omar Lakkis <uofiowa at gmail.com> writes:

> I want to generate a sequence from 1 to x by 1
> seq(1,x,by=1)
> I want the above to return an empty list if x is zero
> In other languages I can do 1:x:1 to force the increment by to be a
> positive 1. This syntax does not work in R. In R 1:x gives me
> 1 0
> when x is zero, this is not what I want.
> The seq statement above throws an error when x is 0. 
> How can I generate a sequence where if the "to" value is less than the
> "from" value an empty list is generated with no errors?

Provide a length argument. In your case, seq(length=x) should suffice. 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list