sequence Create A Vector of Sequences

Description

The default method for sequence generates the sequence seq(from[i], by = by[i], length.out = nvec[i]) for each element i in the parallel (and recycled) vectors from, by and nvec. It then returns the result of concatenating those sequences.

Usage

sequence(nvec, ...)
## Default S3 method:
sequence(nvec, from = 1L, by = 1L, ...)

Arguments

nvec

coerced to a non-negative integer vector each element of which specifies the length of a sequence.

from

coerced to an integer vector each element of which specifies the first element of a sequence.

by

coerced to an integer vector each element of which specifies the step size between elements of a sequence.

...

additional arguments passed to methods.

Details

Negative values are supported for from and by. sequence(nvec, from, by=0L) is equivalent to rep(from, each=nvec).

This function was originally implemented in R with fewer features, but it has since become more flexible, and the default method is implemented in C for speed.

Author(s)

Of the current version, Michael Lawrence based on code from the S4Vectors Bioconductor package

See Also

gl, seq, rep.

Examples

sequence(c(3, 2)) # the concatenated sequences 1:3 and 1:2.
#> [1] 1 2 3 1 2
sequence(c(3, 2), from=2L)
#> [1] 2 3 4 2 3
sequence(c(3, 2), from=2L, by=2L)
#> [1] 2 4 6 2 4
sequence(c(3, 2), by=c(-1L, 1L))
#> [1] 1 0 -1 1 2

Copyright (©) 1999–2012 R Foundation for Statistical Computing.
Licensed under the GNU General Public License.