This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Nearest

Nearest[{elem1, elem2, ...}, x]
gives the list of elemi to which x is nearest.
Nearest[{elem1->v1, elem2->v2, ...}, x]
gives the vi corresponding to the elemi to which x is nearest.
Nearest[{elem1, elem2, ...}->{v1, v2, ...}, x]
gives the same result.
Nearest[{elem1, elem2, ...}->Automatic, x]
takes the vi to be successive integers i.
Nearest[data, x, n]
gives the n nearest elemi to x.
Nearest[data]
generates a NearestFunction[...] which can be applied repeatedly to different x.
  • If the elemi are vectors or matrices of numbers, Nearest by default in effect uses the metric Norm[#1-#2]&.
  • For strings, Nearest by default uses the edit distance metric.
  • The following option can be given:
DistanceFunctionAutomaticthe distance metric to use
  • When several elements are returned, the nearest ones are given first.
  • If several elements are at the same distance, they are returned in the order they appear in data.
New in 6