From r.hankin at noc.soton.ac.uk  Fri Jul 27 09:33:18 2007
From: r.hankin at noc.soton.ac.uk (Robin Hankin)
Date: Fri, 27 Jul 2007 08:33:18 +0100
Subject: [Rd] (PR#9811) sequence(c(2, 0, 3)) produces surprising results,
In-Reply-To: <20070727070700.5FF50667EE@slim.kubism.ku.dk>
References: <20070727070700.5FF50667EE@slim.kubism.ku.dk>
Message-ID: <7907062F-BD1F-447C-B45F-81F62504A5EB@noc.soton.ac.uk>


On 27 Jul 2007, at 08:07, ripley at stats.ox.ac.uk wrote:

> This is as doumented, and I think you could say the same thing of  
> seq().
> BTW, sequence() allows negative inputs, and I don't think you want
> sum(input) in that case.
>
> I've never seen the point of sequence(), but it has been around in  
> R for a
> long time.  It is used in packages eRm, extRemes, hydrosanity,  
> klaR, seas.
> Who knows what people have in private code, so I don't see any  
> compelling
> case to change it.  If people want a different version, it would  
> only take
> a minute to write (see below).
>
> We could make seq_len take a vector argument, but as you point out  
> in a
> followup that makes it slower in the common case.  It also changes its
> meaning if a length > 1 vector is supplied, and would speed matter  
> in the
> long-vector case?  What does
>
> sequence0 <- function (nvec)
> {
>      s <- integer(0)
>      for (i in nvec) s <- c(s, seq_len(i))
>      s
> }
>
> not do that is more than a very rare need?
>


My 2 cents:

  Defining

        mySequence <- function(x){unlist(sapply(x,function(i){seq_len 
(i)}))}

is much faster.

Neither sequence0()  nor  mySequence() accepts vectors with any  
element <0
although as Brian Ripley points out, sequence() itself does (which I  
think is
undesirable).






Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743



[Rd] (PR#9811) sequence(c(2, 0, 3)) produces surprising results,
Robin Hankin