nearests: Is x nearest to y?

nearestsR Documentation

Is x nearest to y?

Description

Returns TRUE if x is nearest to y. There are two implementations. nearest_lgl() returns a logical vector when an element of the first argument is nearest to an element of the second argument. nearest_qt_lgl() is similar to nearest_lgl(), but instead determines if an element of the first argument is nearest to some value of the given quantile probabilities. See example for more detail.

Usage

nearest_lgl(x, y)

nearest_qt_lgl(y, ...)

Arguments

x

a numeric vector

y

a numeric vector

...

(if used) arguments to pass to quantile().

Value

logical vector of length(y)

Examples


x <- 1:10
y <- 5:14
z <- 16:25
a <- -1:-5
b <- -1

nearest_lgl(x, y)
nearest_lgl(y, x)

nearest_lgl(x, z)
nearest_lgl(z, x)

nearest_lgl(x, a)
nearest_lgl(a, x)

nearest_lgl(x, b)
nearest_lgl(b, x)

library(dplyr)
heights_near_min <- heights %>%
  filter(nearest_lgl(min(height_cm), height_cm))
  
heights_near_fivenum <- heights %>%
  filter(nearest_lgl(fivenum(height_cm), height_cm))
  
heights_near_qt_1 <- heights %>%
  filter(nearest_qt_lgl(height_cm, c(0.5)))
  
heights_near_qt_3 <- heights %>%
  filter(nearest_qt_lgl(height_cm, c(0.1, 0.5, 0.9)))


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