[R] seqN

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Nov 30 18:36:31 CET 1999


Paul Gilbert <pgilbert at bank-banque-canada.ca> writes:

>  I have  been using a function
> 
> seqN <- function(N) {if (0==length(N)) NULL else if (N<=0) NULL else seq(N)}
> 
> in for loops when I want no looping in the case of a zero value:
> 
> for (i in seqN(m) ) ...
> 
> Since seqN(0) returns NULL this results in for doing no loops (which is much
> more convenient than always checking for m==0). It seems that a function like
> this should be defined in R (and S) but I have never found it. Is there an
> already defined function that does this (or a better way to achieve this
> result)?

Well, not quite, but:

> seq(length=1)
[1] 1
> seq(length=0)
numeric(0)
> seq(length=3)
[1] 1 2 3
> seq(length=-1)
Error: Length must be non-negative number


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list