The seq
man page states the following (emphasis mine):
Description
Generate regular sequences.
seq
is a standard generic with a default method.seq.int
is a primitive which can be much faster but has a few restrictions.
The page doesn't actually describe what those restrictions are, though. Here's every other mention of seq.int
there:
Arguments
[...]
length.out
desired length of the sequence. A non-negative number, which forseq
andseq.int
will be rounded up if fractional.[...]
Details
[...]
The interpretation of the unnamed arguments of
seq
andseq.int
is not standard, and it is recommended always to name the arguments when programming.[...]
seq.int
is an internal generic which dispatches on methods for "seq
" based on the class of the first supplied argument (before argument matching).
seq.int
,seq_along
andseq_len
are primitive.Value
seq.int
and the default method ofseq
for numeric arguments return a vector of type "integer
" or "double
": programmers should not rely on which.
Other than stating that seq.int
dispatches seq
according to the class of its first argument, I don't see any "restrictions".
So, what are these restrictions?
seq() function in R Language is used to create a sequence of elements in a Vector. It takes the length and difference between values as optional argument.
seq.int is an internal generic which dispatches on methods for "seq" based on the class of the first supplied argument (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 simplest way to create a sequence of numbers in R is by using the : operator. Type 1:20 to see how it works. That gave us every integer between (and including) 1 and 20 (an integer is a positive or negative counting number, including 0).
The seq_along() in R is a built-in function that creates a vector that contains a sequence of numbers from 1 to the object's length. Thus, the seq_along() function creates a sequence the same length of the argument passed, and in the context of a for loop, is used to more easily create the index to iterate over.
seq
is a standard generic function written in R. seq.int
is a primitive function written in C. While both of them are written to do the same job, due do the quirks of their platforms, they can sometimes have certain restrictions. The following is an example.
Note that this is from an old version of R
and is fixed in the current versions. These kinds of bugs have been observed throughout the development of R and they have been patched as soon as possible. The current versions of seq and seq.int now look almost identical. So, there should not be any more restrictions on seq.int
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With