Sequences of Numbers

DESCRIPTION:
Creates a vector of evenly spaced numbers. The beginning, end, spacing and length of the sequence can be specified.

This function is generic (see Methods); method functions can be written to handle specific classes of data. Classes which already have methods for this function include: dates.


USAGE:
seq(...)

seq.default(from=<<see below>>, to=<<see below>>, by=<<see below>>, length=<<see below>>, along=NULL)

from:to # as operator


OPTIONAL ARGUMENTS:
from:
starting value of the sequence. If to, by and length are all given, the value for this is inferred; otherwise, the default is 1. This is required in the operator form.
to:
ending value of sequence, a value less than from is allowed. If from, by and length are all given, the value for this is inferred; otherwise, the default is 1. This is required in the operator form.
by:
spacing between successive values in the sequence. If from, to and length are all given, the value for this is inferred; otherwise, the default is 1.
length:
number of values in the result. If from, to and by are all given, the value for this is inferred.
along:
an object. The length of the object is used as the length of the returned value.

It is an error to specify all of the first four arguments.


VALUE:
a numeric vector with values (from, from+by, from+2*by, ... to). from may be larger or smaller than to. If by is specified, it must have the appropriate sign to generate a finite sequence.

DETAILS:
If there is one unnamed argument that is of length 1 and numeric, then a sequence from 1 to the value of the argument is returned with step sizes of 1.

If the difference between from and to is not a multiple of by, then the sequence stops at the last value not past to.

To generate a sequence from 1 to length(x) to parallel an object x, use seq(along=x). This same behavior results from giving seq a single unnamed argument that is not numeric. The expression seq(along=x) produces the desired result even if the length of x is 0 or 1. Except for these two cases, either seq(x) or 1:length(x) will produce the same result.


NOTE:
The : operator has a high precedence (see Syntax); for example, to create a sequence from 1 to n-1, parentheses are needed 1:(n-1).

SEE ALSO:
seq.dates , rep , c .

EXAMPLES:
seq(5) # 1, 2, 3, 4, 5 # the same thing as 1:5
5:1 # 5, 4, 3, 2, 1
seq(-5) # 1, 0, -1, -2, -3, -4, -5
1.1 : 5 # 1.1, 2.1, 3.1, 4.1
seq(0, 1, .01) # 0, .01, .02, .03, ..., 1.
seq(-pi, pi, length=100)   # 100 values from -pi to pi