seq                   package:base                   R Documentation

_S_e_q_u_e_n_c_e _G_e_n_e_r_a_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     seq(...)

     ## Default S3 method:
     seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
         length.out = NULL, along.with = NULL, ...)

     seq.int(from, to, by, length.out, along.with, ...)

     seq_along(along.with)
     seq_len(length.out)

_A_r_g_u_m_e_n_t_s:

     ...: arguments passed to or from methods.

from, to: the starting and (maximal) end value of the sequence.

      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.

_D_e_t_a_i_l_s:

     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.

     Both 'seq' are 'seq.int' are generic, and only the default method
     is described here.  Typical usages are


     seq(from, to)
     seq(from, to, by= )
     seq(from, to, length.out= )
     seq(along.with= )
     seq(from)
     seq(length.out= )

     The first form generates the sequence 'from, from+/-1, ..., to'
     (identical to 'from:to').

     The second form generates 'from, from+by', ..., up to the sequence
     value less than or equal to 'to'.  Specifying 'to - from' and 'by'
     of opposite signs is an error.  Note that the computed final value
     can go just beyond 'to' to allow for rounding error, but (as from
     R 2.9.0) is truncated to 'to'.

     The third generates a sequence of 'length.out' equally spaced
     values from 'from' to 'to'.  ('length.out' is usually abbreviated
     to 'length' or 'len', and 'seq_len' is much faster.)

     The fourth form generates the sequence '1, 2, ...,
     length(along.with)'.  ('along.with' is usually abbreviated to
     'along', and 'seq_along' is much faster.) 

     The fifth form generates the sequence '1, 2, ..., length(from)'
     (as if argument 'along.with' had been specified), _unless_ the
     argument is numeric of length 1 when it is interpreted as '1:from'
     (even for 'seq(0)' for compatibility with S).

     The final form generates '1, 2, ..., length.out' unless
     'length.out = 0', when it generates 'integer(0)'.

     Very small sequences (with 'from - to' of the order of 10^{-14}
     times the larger of the ends) will return 'from'.

     For 'seq'(only), up to two of 'from', 'to' and 'by' can be
     supplied as complex values provided 'length.out' or 'along.with'
     is specified.

     'seq.int', 'seq_along' and 'seq_len' are primitive: the latter two
     ignore any argument name.

_V_a_l_u_e:

     Currently, 'seq.int' and the default method of 'seq' return a
     result of type '"integer"' (if it is representable as that and) if
     'from' is (numerically equal to an) integer and, e.g., only 'to'
     is specified, or also if only 'length' or only 'along.with' is
     specified.  *Note:* this may change in the future and programmers
     should not rely on it.

     'seq_along' and 'seq_length' always return an integer vector.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     The methods 'seq.Date' and 'seq.POSIXt'.

     ':', 'rep', 'sequence', 'row', 'col'.

_E_x_a_m_p_l_e_s:

     seq(0, 1, length.out=11)
     seq(stats::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

