next_discrete() and prev_discrete() find the n discrete values
in a numeric series next to a reference point. num_discretes() finds
the number of discrete values within a range.
Arguments
- x
Numeric series (
numericvector or object of class"discretes").- from
Reference value to start searching from; single numeric.
- ...
Reserved for future extensions; must be empty.
- n
Number of discrete values to find; single positive integer.
- include_from
Should the
fromvalue be included in the query? Single logical; defaults toTRUE.- tol
Numerical tolerance when checking if a value is in the series. Single non-negative numeric. See
next_discrete()for details.
Value
A vector of sequential points starting from from, which is
included in the vector if it is a discrete value in the numeric series and
include_from = TRUE. The length of the vector is at most n, and
will return an empty numeric vector if there is no such discrete
value. next_discrete() is increasing, while prev_discrete() is
decreasing, so that earlier values are encountered sooner.
Details
For a transformed or combined series (e.g. 1 / integers()), traversal is
delegated to the base series, and tol is passed through to those calls.
This means that tol is only realized on the underlying series:
Numeric vector (or
as_discretes(...)): a value is a member if it is withintolof a stored value.Arithmetic series: the implied step index (distance from the representative in steps) is treated as an integer if it is within
tolof an integer. See the Tolerance vignette for examples.
Examples
x <- integers(from = 2)
next_discrete(x, from = 1.3)
#> [1] 2
prev_discrete(x, from = 4, n = 10)
#> [1] 3 2
next_discrete(x - 0.7, from = 1.3, n = 4)
#> [1] 2.3 3.3 4.3 5.3
