Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

seq: Sequence Generation

seqR Documentation

Sequence Generation

Description

Generate regular sequences.seq is a standard generic with adefault method.seq.int is a primitive which can bemuch faster but has a few restrictions.seq_along andseq_len are very fast primitives for two common cases.

Usage

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)

Arguments

...

arguments passed to or from methods.

from, to

the starting and (maximal) end values of thesequence. Of length1 unless justfrom is supplied asan unnamed argument.

by

number: increment of the sequence.

length.out

desired length of the sequence. Anon-negative number, which forseq andseq.int will berounded up if fractional.

along.with

take the length from the length of this argument.

Details

Numerical inputs should all be finite (that is, not infinite,NaN orNA).

The interpretation of the unnamed arguments ofseq andseq.int isnot standard, and it is recommended always toname the arguments when programming.

seq is generic, and only the default method is described here.Note that it dispatches on the class of thefirst argumentirrespective of argument names. This can have unintended consequencesif it is called with just one argument intending this to be taken asalong.with: it is much better to useseq_along in thatcase.

seq.int is an internal generic which dispatches onmethods for"seq" based on the class of the first suppliedargument (before argument matching).

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 sequencefrom, from+/-1, ..., to(identical tofrom:to).

The second form generatesfrom, from+by, ..., up to thesequence value less than or equal toto. Specifyingto - from andby of opposite signs is an error. Note that thecomputed final value can go just beyondto to allow forrounding error, but is truncated toto. (‘Just beyond’is by up to1e-10 timesabs(from - to).)

The third generates a sequence oflength.out equally spacedvalues fromfrom toto. (length.out is usuallyabbreviated tolength orlen, andseq_len is muchfaster.)

The fourth form generates the integer sequence1, 2, ..., length(along.with). (along.with is usually abbreviated toalong, andseq_along is much faster.)

The fifth form generates the sequence1, 2, ..., length(from)(as if argumentalong.with had been specified),unlessthe argument is numeric of length 1 when it is interpreted as1:from (even forseq(0) for compatibility with S).Using eitherseq_along orseq_len is much preferred(unless strict S compatibility is essential).

The final form generates the integer sequence1, 2, ..., length.out unlesslength.out = 0, when it generatesinteger(0).

Very small sequences (withfrom - to of the order of10^{-14}times the larger of the ends) will returnfrom.

Forseq (only), up to two offrom,to andby can be supplied as complex values providedlength.outoralong.with is specified. More generally, the default methodofseq will handle classed objects with methods fortheMath,Ops andSummary group generics.

seq.int,seq_along andseq_len areprimitive.

Value

seq.int and the default method ofseq for numericarguments return a vector of type"integer" or"double":programmers should not rely on which.

seq_along andseq_len return an integer vector, unlessit is along vector when it will be double.

References

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

See Also

The methodsseq.Date andseq.POSIXt.

:,rep,sequence,row,col.

Examples

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)

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp