Sequences of Numbers

DESCRIPTION:

Creates a vector or bdVector of evenly spaced numbers. The start, end, spacing, and length of the sequence can be specified.

This function is an S Version 3 generic method (see the help file for Methods). Method functions can be written to handle specific S Version 3 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.out=<<see below>>, along.with=NULL, bigdata=F)  
from:to    # the operator 

OPTIONAL ARGUMENTS:

from
starting value of the sequence. This argument is required by : (the colon operator). If to, by, and length are all given, the value for from is inferred. Otherwise, the default is 1.
to
ending value of the sequence. This argument is required by : (the colon operator). If from, by, and length are all given, the value for to is inferred. Otherwise, the default is 1. A value of to that is less than from is allowed.
by
spacing between successive values in the sequence. If from, to, and length are all given, the value for by is inferred. Otherwise, the default is 1.
length.out
number of values in the sequence. If from, to, and by are all given, the value for length is inferred.
along.with
an object: the length of the object is used as the length of the sequence.
bigdata
a logical value. If TRUE, an object of type bdVector is returned. Otherwise, a vector object is returned. This argument can be used only if the bigdata library section has been loaded.
It is an error to specify all of the first four arguments.

VALUE:

a numeric vector or bdVector with values ( from, from+by, from+2*by, ..., to).

The from value may be larger or smaller than the to value. If by is specified, it must have the appropriate sign for a finite sequence to be generated; i.e., by must be negative if from is larger than to. If the difference between from and to is not a multiple of by, the sequence stops at the last value that is not past to.

DETAILS:

If seq is called with one unnamed, numeric argument of length 1, an integer sequence from 1 to the value of the argument is returned. For example, the command seq(4) returns the integers 1, 2, 3, 4.

To generate an integer sequence from 1 to length(x) for an object x, use one of the following commands: seq(along=x), seq(x), or 1:length(x). If x has length 0 or 1, seq(along=x) produces a sequence of length 0 or 1, while seq(x) returns the integer sequence from 1 to x.

NOTES:

The colon operator has a high precedence (see the help file for Syntax). Thus, for example, parentheses are needed to create a sequence from 1 to n-1: use the command 1:(n-1) instead of 1:n-1. If you omit the parentheses, S-PLUS instead subtracts 1 from each of the values in the sequence 1:n.

If by is very small and to is specified, the final element in the returned sequence may not equal to (although it will be extremely close). This is due to finite precision arithmetic, which you can work around with a different choice of operators. For example, the sequence produced by seq(0,1,by=1/n) may not end exactly at 1 if n is very large. Instead, you can use the commands seq(0,1,length=n+1) or 0:n/n to create a sequence that ends in 1.

SEE ALSO:

, , .

EXAMPLES:

# Two ways to obtain the sequence 1, 2, 3, 4, 5.
seq(5) 
1:5
# The sequence 5, 4, 3, 2, 1.
5:1
# Integer sequence from 1 to -5.
seq(-5) 
# The sequence 1.1, 2.1, 3.1, 4.1.
1.1 : 5
# The sequence 0, 0.01, 0.02, ..., 1.  
seq(0, 1, by=0.01)
# 100 values from -pi to pi.
seq(-pi, pi, length=100)