seqM: seqM

Description Usage Arguments Details Value Comparison See Also Examples

View source: R/rpraat.R

Description

Matlab-like behaviour of colon operator or linspace for creating sequences, for-loop friendly.

Usage

1
seqM(from = NA, to = NA, by = NA, length.out = NA)

Arguments

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 parameter). If both by and length.out are not specified, then by = +1.

length.out

desired length of the sequence (if specified, do not use the by parameter)

Details

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.

Value

returns a vector of type "integer" or "double"

Comparison

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

See Also

round2, isNum, isInt, ifft.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
seqM(1, 3)
seqM(1, 3, by=.8)
seqM(1, 3, by=5)
seqM(3, 1)
seqM(3, 1, by=+1)
seqM(3, 1, by=-1)
seqM(3, 1, by=-3)
seqM(1, 3, len=5)
seqM(1, 3, len=3)
seqM(1, 3, len=2)
seqM(1, 3, len=1)
seqM(1, 3, len=0)
seqM(3, 1, len=3)

rPraat documentation built on Dec. 9, 2018, 1:04 a.m.