Generate a sequence over the range of a vector

seq_range(x, n, by, trim = NULL, expand = NULL, pretty = FALSE)

Arguments

x

A numeric vector

n, by

Specify the output sequence either by supplying the length of the sequence with n, or the spacing between value with by. Specifying both is an error.

I recommend that you name these arguments in order to make it clear to the reader.

trim

Optionally, trim values off the tails. trim / 2 * length(x) values are removed from each tail.

expand

Optionally, expand the range by expand * (1 + range(x) (computed after trimming).

pretty

If TRUE, will generate a pretty sequence. If n is supplied, this will use pretty() instead of seq(). If by is supplied, it will round the first value to a multiple of by.

Examples

x <- rcauchy(100) seq_range(x, n = 10)
#> [1] -34.949074 -21.837823 -8.726572 4.384679 17.495931 30.607182 #> [7] 43.718433 56.829684 69.940935 83.052187
seq_range(x, n = 10, trim = 0.1)
#> [1] -6.47023804 -4.84759965 -3.22496126 -1.60232287 0.02031551 1.64295390 #> [7] 3.26559229 4.88823068 6.51086907 8.13350746
seq_range(x, by = 1, trim = 0.1)
#> [1] -6.470238 -5.470238 -4.470238 -3.470238 -2.470238 -1.470238 -0.470238 #> [8] 0.529762 1.529762 2.529762 3.529762 4.529762 5.529762 6.529762 #> [15] 7.529762
# Make pretty sequences y <- runif(100) seq_range(y, n = 10)
#> [1] 0.003709545 0.113536504 0.223363462 0.333190420 0.443017378 0.552844336 #> [7] 0.662671295 0.772498253 0.882325211 0.992152169
seq_range(y, n = 10, pretty = TRUE)
#> [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
seq_range(y, n = 10, expand = 0.5, pretty = TRUE)
#> [1] -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4
seq_range(y, by = 0.1)
#> [1] 0.003709545 0.103709545 0.203709545 0.303709545 0.403709545 0.503709545 #> [7] 0.603709545 0.703709545 0.803709545 0.903709545
seq_range(y, by = 0.1, pretty = TRUE)
#> [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0