EVOLUTION-MANAGER
Edit File: seq.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Sequence Generation</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for seq {base}"><tr><td>seq {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Sequence Generation</h2> <h3>Description</h3> <p>Generate regular sequences. <code>seq</code> is a standard generic with a default method. <code>seq.int</code> is a primitive which can be much faster but has a few restrictions. <code>seq_along</code> and <code>seq_len</code> are very fast primitives for two common cases. </p> <h3>Usage</h3> <pre> 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) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p>arguments passed to or from methods.</p> </td></tr> <tr valign="top"><td><code>from, to</code></td> <td> <p>the starting and (maximal) end values of the sequence. Of length <code>1</code> unless just <code>from</code> is supplied as an unnamed argument.</p> </td></tr> <tr valign="top"><td><code>by</code></td> <td> <p>number: increment of the sequence.</p> </td></tr> <tr valign="top"><td><code>length.out</code></td> <td> <p>desired length of the sequence. A non-negative number, which for <code>seq</code> and <code>seq.int</code> will be rounded up if fractional.</p> </td></tr> <tr valign="top"><td><code>along.with</code></td> <td> <p>take the length from the length of this argument.</p> </td></tr> </table> <h3>Details</h3> <p>Numerical inputs should all be <a href="is.finite.html">finite</a> (that is, not infinite, <code><a href="is.finite.html">NaN</a></code> or <code>NA</code>). </p> <p>The interpretation of the unnamed arguments of <code>seq</code> and <code>seq.int</code> is <em>not</em> standard, and it is recommended always to name the arguments when programming. </p> <p><code>seq</code> is generic, and only the default method is described here. Note that it dispatches on the class of the <strong>first</strong> argument irrespective of argument names. This can have unintended consequences if it is called with just one argument intending this to be taken as <code>along.with</code>: it is much better to use <code>seq_along</code> in that case. </p> <p><code>seq.int</code> is an <a href="InternalMethods.html">internal generic</a> which dispatches on methods for <code>"seq"</code> based on the class of the first supplied argument (before argument matching). </p> <p>Typical usages are </p> <pre>seq(from, to) seq(from, to, by= ) seq(from, to, length.out= ) seq(along.with= ) seq(from) seq(length.out= ) </pre> <p>The first form generates the sequence <code>from, from+/-1, ..., to</code> (identical to <code>from:to</code>). </p> <p>The second form generates <code>from, from+by</code>, ..., up to the sequence value less than or equal to <code>to</code>. Specifying <code>to - from</code> and <code>by</code> of opposite signs is an error. Note that the computed final value can go just beyond <code>to</code> to allow for rounding error, but is truncated to <code>to</code>. (‘Just beyond’ is by up to <i>1e-10</i> times <code>abs(from - to)</code>.) </p> <p>The third generates a sequence of <code>length.out</code> equally spaced values from <code>from</code> to <code>to</code>. (<code>length.out</code> is usually abbreviated to <code>length</code> or <code>len</code>, and <code>seq_len</code> is much faster.) </p> <p>The fourth form generates the integer sequence <code>1, 2, ..., length(along.with)</code>. (<code>along.with</code> is usually abbreviated to <code>along</code>, and <code>seq_along</code> is much faster.) </p> <p>The fifth form generates the sequence <code>1, 2, ..., length(from)</code> (as if argument <code>along.with</code> had been specified), <em>unless</em> the argument is numeric of length 1 when it is interpreted as <code>1:from</code> (even for <code>seq(0)</code> for compatibility with S). Using either <code>seq_along</code> or <code>seq_len</code> is much preferred (unless strict S compatibility is essential). </p> <p>The final form generates the integer sequence <code>1, 2, ..., length.out</code> unless <code>length.out = 0</code>, when it generates <code>integer(0)</code>. </p> <p>Very small sequences (with <code>from - to</code> of the order of <i>10^{-14}</i> times the larger of the ends) will return <code>from</code>. </p> <p>For <code>seq</code> (only), up to two of <code>from</code>, <code>to</code> and <code>by</code> can be supplied as complex values provided <code>length.out</code> or <code>along.with</code> is specified. More generally, the default method of <code>seq</code> will handle classed objects with methods for the <code>Math</code>, <code>Ops</code> and <code>Summary</code> group generics. </p> <p><code>seq.int</code>, <code>seq_along</code> and <code>seq_len</code> are <a href="Primitive.html">primitive</a>. </p> <h3>Value</h3> <p><code>seq.int</code> and the default method of <code>seq</code> for numeric arguments return a vector of type <code>"integer"</code> or <code>"double"</code>: programmers should not rely on which. </p> <p><code>seq_along</code> and <code>seq_len</code> return an integer vector, unless it is a <em>long vector</em> when it will be double. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p>The methods <code><a href="seq.Date.html">seq.Date</a></code> and <code><a href="seq.POSIXt.html">seq.POSIXt</a></code>. </p> <p><code><a href="Colon.html">:</a></code>, <code><a href="rep.html">rep</a></code>, <code><a href="sequence.html">sequence</a></code>, <code><a href="row.html">row</a></code>, <code><a href="col.html">col</a></code>. </p> <h3>Examples</h3> <pre> 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) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>