Selecting closest values
P_M <pmartinu at broadpark.no> [Sun, Mar 22, 2009 at 06:48:36PM CET]:
Hi I have a table with ID (1 to 183) and Location (144 to -22). My problem is that I want to select the 10 ID's that are closest in Location to ID 1, ID 2 and so on. Also, some ID have the same Location. Say, if 11 ID's are closest to ID 100 I want to randomly choose one of the ID's to select 10 ID's total.
In the general case, the nn function from the RANN package (not part of CRAN but found by rseek) does what you want, but for the one-dimensional case this might be overkill.
Johannes H?sing There is something fascinating about science.
One gets such wholesale returns of conjecture
mailto:johannes at huesing.name from such a trifling investment of fact.
http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")