Which values are nearest to any given quantiles
Arguments
- x
vector
- probs
quantiles to calculate
- tol
tolerance in terms of x that you will accept near to the quantile. Default is 0.01.
Examples
x <- runif(20)
near_quantile(x, 0.5, 0.05)
#> [1] FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
near_quantile(x, c(0.25, 0.5, 0.75), 0.05)
#> [1] FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE
#> [13] FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE
library(dplyr)
heights %>%
features(height_cm, list(min = min)) %>%
mutate(min_near_median = near_quantile(min, 0.5, 0.01)) %>%
filter(min_near_median)
#> # A tibble: 0 × 3
#> # ℹ 3 variables: country <chr>, min <dbl>, min_near_median <lgl>
heights %>%
features(height_cm, 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: 2 × 3
#> country min min_near_q3
#> <chr> <dbl> <lgl>
#> 1 Ethiopia 161. TRUE
#> 2 Madagascar 161. TRUE