[Rd] sequence(c(2, 0, 3)) produces surprising results, would like output length to be sum(input) (PR#9811)

From: <bill_at_insightful.com>
Date: Thu, 26 Jul 2007 19:45:28 +0200 (CEST)

Full_Name: Bill Dunlap
Version: 2.5.0
OS: Linux
Submission from: (NULL) (

sequence(nvec) is documented to return
the concatenation of seq(nvec[i]), for
i in seq(along=nvec). This produces inconvenient (for me) results for 0 inputs.

> sequence(c(2,0,3)) # would like 1 2 1 2 3, ignore 0
    [1] 1 2 1 0 1 2 3
Would changing sequence(nvec) to use seq_len(nvec[i]) instead of the current 1:nvec[i] break much existing code?

On the other hand, almost no one seems to use sequence() and it might make more sense to allow seq_len() and seq() to accept a vector for length.out and they would return a vector of length sum(length.out),

    c(seq_len(length.out[1]), seq_len(length.out[2]), ...)

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 26 Jul 2007 - 17:47:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 26 Jul 2007 - 19:36:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.