ID EN
Miscellaneous

seq

R Base 3.6.2

Generate regular sequences. seq is a standard generic with a default method. seq.int is a primitive which can be much faster but has a few restrictions. seq_along and seq_len are very fast primitives for two common cases.

Syntax

R
seq(&#8230;)<p></p><p># S3 method for default
seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
    length.out = NULL, along.with = NULL, &#8230;)</p><p>seq.int(from, to, by, length.out, along.with, &#8230;)</p><p>seq_along(along.with)
seq_len(length.out)</p>

Arguments

Parameter Description
&#8230; arguments passed to or from methods.
from, to the starting and (maximal) end values of the sequence. Of length 1 unless just from is supplied as an unnamed argument.
by number: increment of the sequence.
length.out desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional.
along.with take the length from the length of this argument.

Return Value

seq.int and the default method of seq for numeric arguments return a vector of type "integer" or "double": programmers should not rely on which. seq_along and seq_len return an integer vector, unless it is a long vector when it will be double.

Details

Numerical inputs should all be finite (that is, not infinite, NaN or NA). The interpretation of the unnamed arguments of seq and seq.int is not standard, and it is recommended always to name the arguments when programming. seq is generic, and only the default method is described here. Note that it dispatches on the class of the first argument irrespective of argument names. This can have unintended consequences if it is called with just one argument intending this to be taken as along.with: it is much better to use seq_along in that case. seq.int is an internal generic which dispatches on methods for "seq" based on the class of the first supplied argument (before argument matching). Typical usages areseq(from, to) seq(from, to, by= ) seq(from, to, length.out= ) seq(along.with= ) seq(from)

Examples

Example
R
# NOT RUN {
seq(0, 1, length.out = 11)
seq(stats::rnorm(20)) # effectively 'along'
seq(1, 9, by = 2)     # matches 'end'
seq(1, 9, by = pi)    # stays below 'end'
seq(1, 6, by = 3)
seq(1.575, 5.125, by = 0.05)
seq(17) # same as 1:17, or even better seq_len(17)
# }

See Also

The methods seq.Date and seq.POSIXt. : rep sequence row col.