Generate a sequence over the range of a vector
seq_range(x, n, by, trim = NULL, expand = NULL, pretty = FALSE)
A numeric vector
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.
Optionally, trim values off the tails.
trim / 2 * length(x)
values are removed from each tail.
Optionally, expand the range by expand * (1 + range(x)
(computed after trimming).
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
.
x <- rcauchy(100)
seq_range(x, n = 10)
#> [1] -147.37233 -11.16743 125.03748 261.24238 397.44728 533.65218
#> [7] 669.85709 806.06199 942.26689 1078.47179
seq_range(x, n = 10, trim = 0.1)
#> [1] -5.2012577 -3.8116357 -2.4220137 -1.0323918 0.3572302 1.7468522
#> [7] 3.1364742 4.5260962 5.9157181 7.3053401
seq_range(x, by = 1, trim = 0.1)
#> [1] -5.2012577 -4.2012577 -3.2012577 -2.2012577 -1.2012577 -0.2012577
#> [7] 0.7987423 1.7987423 2.7987423 3.7987423 4.7987423 5.7987423
#> [13] 6.7987423
# Make pretty sequences
y <- runif(100)
seq_range(y, n = 10)
#> [1] 0.001478486 0.110582139 0.219685792 0.328789445 0.437893099 0.546996752
#> [7] 0.656100405 0.765204058 0.874307711 0.983411365
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.001478486 0.101478486 0.201478486 0.301478486 0.401478486 0.501478486
#> [7] 0.601478486 0.701478486 0.801478486 0.901478486
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