| seq {base} | R Documentation |
Generate regular sequences.
from:to seq(from, to) seq(from, to, by=) seq(from, to, length=) seq(along)
from |
starting value of sequence. |
to |
(maximal) end value of the sequence. |
by |
increment of the sequence. |
length |
desired length of the sequence. |
along |
take the length from the length of this argument. |
The interpretation of the unnamed arguments of seq is
not standard, and it is recommended to always name the
arguments when programming.
The operator : and the first seq(.) form generate the
sequence from, from+1, ..., to.
seq is a generic function.
The second form generates from, from+by, ..., to.
The third generates a sequence of length equally spaced values
from from to to.
The last generates the sequence 1, 2, ...,
length(along), unless the argument is of length 1 when it is
interpreted as a length argument.
If from and to are factors of the same length, then
from : to returns the ``cross'' of the two.
Very small sequences (with from - to of the order of 1e-14
times the larger of the ends) will return from.
The result is of mode "integer" if from is
(numerically equal to an) integer and by is not specified.
1:4
pi:6 # float
6:pi # integer
seq(0,1, length=11)
str(seq(rnorm(20)))
seq(1,9, by = 2) # match
seq(1,9, by = pi)# stay below
seq(1,6, by = 3)
seq(1.575, 5.125, by=0.05)
seq(17) # same as 1:17
for (x in list(NULL, letters[1:6], list(1,pi)))
cat("x=",deparse(x),"; seq(along = x):",seq(along = x),"\n")
f1 <- gl(2,3); f1
f2 <- gl(3,2); f2
f1:f2 # a factor, the ``cross'' f1 x f2