[R] seq curiosity
Henrik Bengtsson
hb at maths.lth.se
Fri May 3 13:10:19 CEST 2002
> -----Original Message-----
> From: owner-r-help at stat.math.ethz.ch
> [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of Peter Dalgaard BSA
> Sent: Friday, May 03, 2002 11:18 AM
> To: Uwe Ligges
> Cc: jaitchis at hwy.com.au; r-help at stat.math.ethz.ch
> Subject: Re: [R] seq curiosity
>
>
> Uwe Ligges <ligges at statistik.uni-dortmund.de> writes:
>
> > John Aitchison wrote:
> > >
> > > Is this a bug or a feature?
> > >
> > > > seq(0:4) # colon
> > > [1] 1 2 3 4 5
> > > > 0:4
> > > [1] 0 1 2 3 4
> > > > seq(0,4)
> > > [1] 0 1 2 3 4
> > >
> > > I am aware that the first usage is incorrect, but I was surprised that
> > > I did not get any sort of syntax error
> >
> > It's a feature! It's mentioned in the help page. If you provide a vector
> > (length > 1) as an argument to seq(), seq() is smart enough to detect
> > the case "seq(along)":
> >
> > along <- 0:4
> > seq(along)
> >
> > The same should happen for
> >
> > along <- LETTERS[10:14]
> > along
> > seq(along)
> >
> > Everything works perfectly!
>
> Well, almost. The case where x is numeric and length(x) == 1 is the
> source of some subtle and nasty bugs. Try a couple of iterations of
>
> x <- rnorm(20, sd=100) ; seq(x[x>100])
>
> and you'll see the problem.
>
> However, we probably have to retain it for compatibility.
...which is actually no problem if one is more explicit:
x <- rnorm(20, sd=100) ; seq(along=x[x>100])
(as most of you already know)
Henrik Bengtsson
Dept. of Mathematical Statistics @ Centre for Mathematical Sciences
Lund Institute of Technology/Lund University, Sweden (+2h UTC)
Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax)
h b @ m a t h s . l t h . s e, http://www.maths.lth.se/bioinformatics/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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