Skip to contents

stm_arange() generates a sequence of values from from to to with a specified step size (by), optionally including the last value to if it is not already in the sequence.

Usage

stm_arange(from = NULL, to = NULL, by = 1, include_last = FALSE, digits = NULL)

Arguments

from

Numeric value. The starting value of the sequence. Defaults to 1 if to is provided and from is NULL.

to

Numeric value. The end value of the sequence.

by

Numeric value. The step size between consecutive values. Default is 1.

include_last

Logical value. If TRUE, the sequence will include the last value to if it's not already included. Default is FALSE.

digits

Optional. Number of decimal places to round the sequence.

Value

A numeric vector of values from from to to, spaced by by.

Details

This function generates a sequence of values similar to seq(), with the ability to include the last value (to) if it is not already present in the sequence.

Examples

stm_arange(from = 1, to = 10, by = 2)
#> [1] 1 3 5 7 9
stm_arange(to = 10)
#>  [1]  1  2  3  4  5  6  7  8  9 10
stm_arange(from = 10) # sequence will start from 1 to 10
#>  [1]  1  2  3  4  5  6  7  8  9 10
stm_arange(from = 1, to = 5, by = 0.25)
#>  [1] 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50
#> [16] 4.75 5.00
stm_arange(from = 1, to = 8, by = 2, include_last = TRUE)
#> [1] 1 3 5 7 8