Description Usage Arguments Details Value Comparison See Also Examples
Matlab-like behaviour of colon operator or linspace for creating sequences, for-loop friendly.
1 |
from |
starting value of the sequence (the first number) |
to |
end value of the sequence (the last number or the boundary number) |
by |
increment of the sequence (if specified, do not use the |
length.out |
desired length of the sequence (if specified, do not use the |
Like seq()
but with Matlab-like behavior ([: operator] with by
or [linspace] with length.out
).
If I create a for-loop, I would like to get an empty vector for 3:1
(I want a default step +1)
and also an empty vector for seq(3, 1, by = 1)
(not an error). This is solved by this seqM
function.
returns a vector of type "integer" or "double"
R: seqM | Matlab | R: seq | ||
seqM(1, 3) | [1] 1 2 3 | 1:3 | the same | the same |
seqM(1, 3, by=.8) | [1] 1.0 1.8 2.6 | 1:.8:3 | the same | the same |
seqM(1, 3, by=5) | [1] 1 | 1:5:3 | the same | the same |
seqM(3, 1) | integer(0) | 3:1 | the same | [1] 3 2 1 |
seqM(3, 1, by=+1) | integer(0) | 3:1:1 | the same | Error: wrong 'by' |
seqM(3, 1, by=-1) | [1] 3 2 1 | 3:-1:1 | the same | the same |
seqM(3, 1, by=-3) | [1] 3 | 3:-3:1 | the same | the same |
seqM(1, 3, len=5) | [1] 1.0 1.5 2.0 2.5 3.0 | linspace(1,3,5) | the same | the same |
seqM(1, 3, len=3) | [1] 1 2 3 | linspace(1,3,3) | the same | the same |
seqM(1, 3, len=2) | [1] 1 3 | linspace(1,3,2) | the same | the same |
seqM(1, 3, len=1) | [1] 3 | linspace(1,3,1) | the same | [1] 1 |
seqM(1, 3, len=0) | integer(0) + warning | linspace(1,3,0) | the same without warning | the same without warning |
seqM(3, 1, len=3) | [1] 3 2 1 | linspace(3,1,3) | the same | the same |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.