NearestTo
Details and Options
- NearestTo works for a variety of data, including numerical, geospatial, textual and visual, as well as dates and times.
- NearestTo[x][elems] is equivalent to NearestTo[elems,x].
- NearestTo[x,nr][elems] is equivalent to NearestTo[elems,x,nr], where nr is an integer n or a pair {n,r}.
- NearestTo[x][nf] for a NearestFunction object nf is equivalent to nf[x].
- NearestTo[x,nr][nf] for a NearestFunction object nf is equivalent to nf[x,nr], where nr is an integer n or a pair {n,r}.
Examples
open allclose allBasic Examples (4)
Scope (6)
Give the elements within radius 2:
Give at most 3 nearest elements within radius 2:
Apply NearestTo to a NearestFunction expression:
The same result can be obtained by direct application of nf:
Return the index for the nearest string:
Return an Association giving the string element, index and distance:
Find the 3 elements nearest to 20, simultaneously reporting the elements and their distance to 20:
Find which element is nearest to {2,3} in 2D and return the appropriate label:
Compute the same result using an Association:
Options (1)
DistanceFunction (1)
By default, normal Euclidean distance is used for points:
Use the ManhattanDistance, which sums the length of each side:
The ChessboardDistance only takes into account the dimension with the largest separation:
Applications (3)
Text
Wolfram Research (2018), NearestTo, Wolfram Language function, https://reference.wolfram.com/language/ref/NearestTo.html.
CMS
Wolfram Language. 2018. "NearestTo." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NearestTo.html.
APA
Wolfram Language. (2018). NearestTo. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NearestTo.html