The dist() function will help you find the distance between each pair of points:
set.seed(1)
X<- sample(200:1000,10)
Y<- sample (200:1000, 10)
dat<-data.frame(X,Y)
print(dat)
X Y
1 412 364
2 497 341
3 657 748
4 924 506
5 360 813
6 915 596
7 951 770
8 724 987
9 698 501
10 248 815
dist(dat)
1 2 3 4 5 6 7 8 9
2 88.05680
3 455.50082 437.32025
4 531.32664 457.77068 360.35122
5 452.00111 491.48042 304.02960 642.14095
6 553.92509 489.64171 299.44616 90.44888 595.91442
7 674.80145 624.62549 294.82198 265.37709 592.56223 177.68511
8 696.75893 684.72257 248.21362 520.92322 403.45012 435.15744 314.03503
9 317.11985 256.90660 250.37971 226.05530 459.98696 236.88394 369.28309 486.69498
10 479.89270 535.42226 414.45144 743.27451 112.01786 702.03276 704.43878 506.12251 548.72215
You can then create a matrix that gives you the min distance:
which(as.matrix(dist(dat))==min(dist(dat)),arr.ind=TRUE)
This is the output:
row col
2 2 1
1 1 2
Hope this helped.