Learn R Programming

rmngb (version 0.6-1)

Closest matching: Approximate Matching

Description

These function provide different utilities to perform approximate matching of numbers.

Usage

closest(x, y, tol = +Inf)

Arguments

x
numeric scalar. Value to be approximatly matched.
y
numeric vector of values to be matched with x.
tol
numeric scalar giving the maximum difference in absolute value to perform a match.

Value

closest returns a logical vector the same length as y, TRUE for the closest match(es) within tol bounds and FALSE otherwise.

Details

Proximity is calculated by the absolute value of the difference.

See Also

match.

Examples

Run this code
ref <- seq(1:5)
closest(2.8, ref)
closest(2.5, ref, .1) # no match because of lower tolerance

Run the code above in your browser using DataLab