
Extract discrete values from a numeric series
Source:R/get_discretes_at.R, R/get_discretes_in.R
get_discretes.RdExtract a finite subset of discrete values from a numeric series by asking
for specific values (get_discretes_at()) or by setting a range
(get_discretes_in()). For get_discretes_at(), each value in values is
checked against the series using tol (passed down to the underlying series);
if it is in the series, the corresponding discrete value is returned,
otherwise it is dropped. NA values are kept in place.
Arguments
- x
Numeric series (
numericvector or object of class"discretes").- values
Numeric vector of values to pull from the numeric series
x.- ...
Reserved for future extensions; must be empty.
- tol
Numerical tolerance when checking if a value is in the series. Single non-negative numeric. See
next_discrete()for details.- from, to
Reference values, possibly infinite.
frommust be less than or equal toto; both must be length-1 numeric vectors.- include_from, include_to
Should the
fromvalue be included in the query? Should thetovalue? Both must be length-1 logical vectors.
Value
A numeric vector containing all discrete values in the provided series x:
For
get_discretes_in(), all discrete values betweenfromandto, ordered from smallest to largest.For
get_discretes_at(), the discrete values in the series that match the givenvalues. Whether a value is in the series is decided withtolat the underlying series, returning the discrete values in the series rather than the suppliedvalues. Discrete values not withintolof the suppliedvaluesare dropped.
An error will be thrown in get_discretes_in() if there are infinitely
many points in the range.
Examples
get_discretes_in(integers(), from = 6.6, to = 10.1)
#> [1] 7 8 9 10
get_discretes_in(1 / arithmetic(1, 4, n_left = 3, n_right = 5))
#> [1] -0.33333333 -0.14285714 -0.09090909 0.04761905 0.05882353 0.07692308
#> [7] 0.11111111 0.20000000 1.00000000
get_discretes_at(integers(), values = c(-10, 4, 3.5, 10, NA))
#> [1] -10 4 10 NA
get_discretes_at(integers(), values = 5.5)
#> integer(0)