Which values are nearest to any given quantiles

near_quantile(x, probs, tol = 0.01)

## Arguments

x vector quantiles to calculate tolerance in terms of x that you will accept near to the quantile. Default is 0.01.

## Value

logical vector of TRUE/FALSE if number is close to a quantile

## Examples

x <- runif(20)
near_quantile(x, 0.5, 0.05)
#>  [1] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSEnear_quantile(x, c(0.25, 0.5, 0.75), 0.05)
#>  [1] FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE  TRUE
#> [13]  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE
library(dplyr)
wages %>%
features(ln_wages, list(min = min)) %>%
mutate(min_near_median = near_quantile(min, 0.5, 0.01)) %>%
filter(min_near_median)
#> # A tibble: 30 x 3
#>       id   min min_near_median
#>    <int> <dbl> <lgl>
#>  1   145  1.48 TRUE
#>  2  1417  1.48 TRUE
#>  3  1515  1.48 TRUE
#>  4  1535  1.48 TRUE
#>  5  1731  1.48 TRUE
#>  6  1772  1.48 TRUE
#>  7  2213  1.48 TRUE
#>  8  3272  1.48 TRUE
#>  9  6860  1.48 TRUE
#> 10  6918  1.48 TRUE
#> # … with 20 more rowswages %>%
features(ln_wages, list(min = min)) %>%
mutate(min_near_q3 = near_quantile(min, c(0.25, 0.5, 0.75), 0.01)) %>%
filter(min_near_q3)
#> # A tibble: 66 x 3
#>       id   min min_near_q3
#>    <int> <dbl> <lgl>
#>  1   145  1.48 TRUE
#>  2  1417  1.48 TRUE
#>  3  1515  1.48 TRUE
#>  4  1535  1.48 TRUE
#>  5  1580  1.64 TRUE
#>  6  1595  1.63 TRUE
#>  7  1672  1.63 TRUE
#>  8  1731  1.48 TRUE
#>  9  1772  1.48 TRUE
#> 10  1811  1.64 TRUE
#> # … with 56 more rows