In place of d50 <- which(abs(m[,1] - m[,2]) <= 50), calculate the Euclidian distance
set.seed(137)
the_points <- seq(100:900)
draw <- sample(the_points,200)
x <- draw[1:100]
y <- draw[101:200]
m <- matrix(c(x, y), nrow = length(x))
d50 <- which(abs(m[,1] - m[,2]) <= 50)
m[d50,]
#> [,1] [,2]
#> [1,] 124 135
#> [2,] 490 518
#> [3,] 748 733
#> [4,] 737 775
#> [5,] 567 536
#> [6,] 769 778
#> [7,] 143 183
#> [8,] 38 79
#> [9,] 687 731
#> [10,] 224 261
#> [11,] 219 215
#> [12,] 442 441
#> [13,] 643 653
#> [14,] 430 447
#> [15,] 556 523
#> [16,] 271 268
#> [17,] 729 710
Created on 2020-08-17 by the reprex package (v0.3.0)