| sequence {base} | R Documentation |
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.
Note that nvec is not recycled unless recycle1st
is true, see ‘Details’.
It then returns the result of concatenating those sequences.
Usage
sequence(nvec, ...)
## Default S3 method:
sequence(nvec, from = 1L, by = 1L,
recycle1st = as.logical(Sys.getenv("R_sequence_recycle1st", "false")),...)
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. |
recycle1st |
|
... |
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.
Argument recycle1st is new since R 4.6.0;
currently, the default is FALSE unless the environment variable
R_sequence_recycle1st is set to a true value.
This provides back compatibility with R <= 4.5.z, where from and
by are recycled or shortened to length length(nvec) in case
that is shorter than the maximal length.
The plan is to replace the environment variable with an option
(getOption) defaulting to TRUE and subsequently to
TRUE without a global option, to use R's usual recycling semantic
for all three arguments nvec, from, by.
Author(s)
Of the current version, Michael Lawrence based on code from the S4Vectors Bioconductor package
See Also
Examples
sequence(c(3, 2)) # the concatenated sequences 1:3 and 1:2.
#> [1] 1 2 3 ' 1 2 (using ' to visualize the sub-sequences
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
sequence(3, 1:3) #> 1 ' 1 2 ' 1 2 3
## using 'recycle1st' (in case it makes a difference):
sequence(4, 2:3, recycle1st = FALSE)# back compatible
sequence(4, 2:3, recycle1st = TRUE) # future default