grapes-in-grapes: %in% with tolerance

Description Usage Arguments Value Examples

Description

This function replaces R's default %in% function with an all.equal equivalent. It is slower than the default %in%, but it is comparable to the speed differences between identical and all.equal. It takes a lefthand side (LHS) and righthand side (RHS) vector, evaluates whether each value on the LHS is found somewhere in the RHS, within the matching tolerance, and returns a logical vector of length(LHS). Note that this function only takes tolerance into account if both the LHS and RHS are numeric, otherwise it uses the default %in% behavior.

Usage

1
x %in% y

Arguments

x

a vector whose values are being evaluated for matches in y

y

a vector whose values x is being evaluated for matches in

tol

the tolerance for differences between values of x and y to still be considered a match, by default set to sqrt(.Machine$double.eps)

Value

A logical vector of length x

Examples

1
2
3
4
5
6
7
x <- seq(from = 1, to = 3, by = 0.1)
y <- c(3, 2.4, 1.8, 1.4)
x %in% y

# If you want a different tolerance value you need
# to use the standard function form:
`%in%`(x, y, tol = 0.00001)

MCMaurer/inclose documentation built on Jan. 21, 2020, 7:29 p.m.