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.
nearest_lgl(x, y) nearest_qt_lgl(y, ...)
x | a numeric vector |
---|---|
y | a numeric vector |
... | (if used) arguments to pass to |
logical vector of length(y)
x <- 1:10 y <- 5:14 z <- 16:25 a <- -1:-5 b <- -1 nearest_lgl(x, y)#> [1] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSEnearest_lgl(y, x)#> [1] FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUEnearest_lgl(x, z)#> [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSEnearest_lgl(z, x)#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUEnearest_lgl(x, a)#> [1] TRUE FALSE FALSE FALSE FALSEnearest_lgl(a, x)#> [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSEnearest_lgl(x, b)#> [1] TRUEnearest_lgl(b, x)#> [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSElibrary(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)))