One more way using KDTable.
dt = Open( "$sample_data/big class.jmp" );
// create the input matrix for kdtable: [95 59, 123 61, 74 55, ...
data = (dt:weight << getasmatrix) || (dt:height << getasmatrix);
// create the lookup table
lookup = KDTable( data );
// do an example lookup: find the 10 nearest people to a weight of 100 pounds and height of 60
// inches within a distance of 5. (5 is in the same "units" as weight and pounds...normalize?)
{rowNumbers, distances} = lookup << knearestrows( {10, 5}, [100 60] );
// display the results
For( irow = 1, irow <= N Cols( rowNumbers ), irow++,
rowIndex = rowNumbers[irow];
Write( dt:name[rowIndex], " w=", dt:weight[rowIndex], " h=", dt:height[rowIndex], " d=", distances[irow], "\!n" );
);
/*:
ALFRED w=99 h=64 d=4.12310562561766
CHRIS w=99 h=64 d=4.12310562561766
MARK w=104 h=62 d=4.47213595499958
KATIE w=95 h=59 d=5.09901951359278
so d=4.123 is sqrt((100-99)^2+(60-64)^2). By the time Katie was discovered, the radius of 5 was exceeded, so the requested 10 results were limited by the radius.
KDTable works with K dimensional data; you might only need K=1 (just weight, for example) or K=3 (include age as well). The scaling/normalizing issue is more obvious with age in this data, which has a much smaller range than height or weight. Is the distance from 13 years old to 14 years old more or less than the distance from 75 pounds to 80 pounds?
edit: With just weight, it looks even simpler:
dt = Open( "$sample_data/big class.jmp" );
// create the lookup table
lookup = KDTable( dt:weight << getasmatrix );
// do an example lookup: find the 10 nearest people to a weight of 100 pounds
{rowNumbers, distances} = lookup << knearestrows( {10, 5}, [100] );
// display the results
For( irow = 1, irow <= N Cols( rowNumbers ), irow++,
rowIndex = rowNumbers[irow];
Write( dt:name[rowIndex], " w=", dt:weight[rowIndex], " d=", distances[irow], "\!n" );
);
/*:
ALFRED w=99 d=1
CHRIS w=99 d=1
JOHN w=98 d=2
MARK w=104 d=4
KATIE w=95 d=5
JOE w=105 d=5
MICHAEL w=95 d=5
CLAY w=105 d=5
DANNY w=106 d=6
Craige