near_quantile: Which values are nearest to any given quantiles

View source: R/nearests.R

near_quantileR Documentation

Which values are nearest to any given quantiles

Description

Which values are nearest to any given quantiles

Usage

near_quantile(x, probs, tol = 0.01)

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.

Value

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

Examples

x <- runif(20)
near_quantile(x, 0.5, 0.05)
near_quantile(x, c(0.25, 0.5, 0.75), 0.05)

library(dplyr)
heights %>% 
  features(height_cm, list(min = min)) %>% 
  mutate(min_near_median = near_quantile(min, 0.5, 0.01)) %>%
  filter(min_near_median)
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)

brolgar documentation built on June 22, 2024, 11:24 a.m.