Given a set of locations, this function computes the distances between each possible pair of locations.
Arguments
- x
A vector of x (or longitude) coordinates.
- y
A vector of y (or latitude) coordinates.
- geo
A logical value indicating whether the locations are defined by geographic coordinates (pairs of longitude/latitude values). Default: FALSE.
Author
Simon Garnier, garnier@njit.edu
Examples
x <- rnorm(25)
y <- rnorm(25, sd = 3)
pdist(x, y)
#> 1 2 3 4 5 6 7
#> 1 0.0000000 3.2240522 2.0248881 3.0953165 4.5069717 2.7371471 7.565272
#> 2 3.2240522 0.0000000 4.5090149 5.0712215 7.7029441 2.4361972 4.380604
#> 3 2.0248881 4.5090149 0.0000000 1.1532437 3.6832686 2.7660771 8.466755
#> 4 3.0953165 5.0712215 1.1532437 0.0000000 4.1700517 2.9038622 8.653271
#> 5 4.5069717 7.7029441 3.6832686 4.1700517 0.0000000 6.4139792 11.952372
#> 6 2.7371471 2.4361972 2.7660771 2.9038622 6.4139792 0.0000000 5.767890
#> 7 7.5652722 4.3806036 8.4667552 8.6532709 11.9523721 5.7678899 0.000000
#> 8 5.0630011 8.2652942 4.8359689 5.5447486 1.6275347 7.3965076 12.626914
#> 9 1.8697115 3.9986401 0.5804330 1.2573810 4.2500563 2.1858207 7.894251
#> 10 2.8535710 5.0484634 0.8486345 0.3727410 3.8454849 2.9977950 8.765431
#> 11 3.4064652 2.8890716 3.1415715 3.0221543 6.8247761 0.7056517 5.678521
#> 12 2.8875966 5.6708017 1.1920535 1.5324783 2.6571323 3.9355504 9.657431
#> 13 1.2431578 3.9557180 0.7822196 1.8888143 3.8785334 2.5940653 8.089638
#> 14 7.9243142 5.1416159 8.2727449 8.1444564 11.9386498 5.5253547 2.315868
#> 15 1.6660398 4.8598287 2.3124617 3.4307823 3.0500157 4.2232775 9.222104
#> 16 2.4728539 4.1107374 1.0726071 0.9652047 4.6966600 1.9677985 7.734523
#> 17 6.2492045 9.4612281 5.4314011 5.7994253 1.7776518 8.1796392 13.727857
#> 18 3.7400499 6.2482511 1.7927638 1.3827994 3.0837301 4.2359721 10.002568
#> 19 3.4524571 0.9190981 4.3289236 4.6922109 7.7705203 1.8414995 4.182494
#> 20 4.2276201 3.4362256 3.7928558 3.4668927 7.4582316 1.5255369 5.542109
#> 21 7.3670242 4.1475366 8.5301966 8.8716863 11.8492761 5.9717523 1.199729
#> 22 1.6163378 3.5344049 1.0045267 1.6626284 4.5968346 1.8180925 7.466743
#> 23 0.3928893 3.1645151 1.7359228 2.7579152 4.5395927 2.4066472 7.446708
#> 24 5.2056598 8.4014445 4.3295406 4.7288798 0.6990053 7.0778846 12.643896
#> 25 3.8719368 4.7454620 2.4419585 1.6000411 5.7695338 2.3112592 7.658394
#> 8 9 10 11 12 13 14
#> 1 5.063001 1.8697115 2.8535710 3.4064652 2.8875966 1.2431578 7.924314
#> 2 8.265294 3.9986401 5.0484634 2.8890716 5.6708017 3.9557180 5.141616
#> 3 4.835969 0.5804330 0.8486345 3.1415715 1.1920535 0.7822196 8.272745
#> 4 5.544749 1.2573810 0.3727410 3.0221543 1.5324783 1.8888143 8.144456
#> 5 1.627535 4.2500563 3.8454849 6.8247761 2.6571323 3.8785334 11.938650
#> 6 7.396508 2.1858207 2.9977950 0.7056517 3.9355504 2.5940653 5.525355
#> 7 12.626914 7.8942514 8.7654312 5.6785211 9.6574309 8.0896381 2.315868
#> 8 0.000000 5.3508828 5.1910442 7.9020807 4.0153621 4.8035718 12.877688
#> 9 5.350883 0.0000000 1.0989129 2.5790150 1.7638002 0.7799727 7.696570
#> 10 5.191044 1.0989129 0.0000000 3.1950614 1.1916139 1.6200181 8.346917
#> 11 7.902081 2.5790150 3.1950614 0.0000000 4.2519950 3.1147471 5.160638
#> 12 4.015362 1.7638002 1.1916139 4.2519950 0.0000000 1.7546254 9.409095
#> 13 4.803572 0.7799727 1.6200181 3.1147471 1.7546254 0.0000000 8.101279
#> 14 12.877688 7.6965700 8.3469175 5.1606377 9.4090954 8.1012787 0.000000
#> 15 3.406177 2.5777345 3.0781838 4.8280714 2.4328386 1.8200533 9.567989
#> 16 5.903686 0.6844318 1.0316205 2.1862991 2.0759815 1.4634525 7.346815
#> 17 1.858525 6.0050068 5.5040861 8.5689653 4.3428712 5.6559083 13.700884
#> 18 4.616463 2.2511825 1.2395741 4.4007528 0.9877602 2.5243584 9.526631
#> 19 8.500938 3.7710330 4.7343970 2.1335329 5.5198378 3.9091347 4.537955
#> 20 8.609555 3.2589724 3.7026366 0.8255507 4.8326894 3.8633068 4.701208
#> 21 12.376703 7.9776840 8.9351490 6.0229960 9.7180412 8.0580466 3.493031
#> 22 5.609627 0.4644977 1.5481021 2.2939206 2.1961930 0.8313913 7.343424
#> 23 5.214867 1.5132792 2.5390085 3.0590062 2.7020560 0.9739679 7.700053
#> 24 1.628131 4.9028539 4.4231833 7.4680474 3.2515546 4.5626017 12.598727
#> 25 7.130769 2.1479640 1.9410294 2.0455803 3.1288913 2.9274545 6.836917
#> 15 16 17 18 19 20 21
#> 1 1.666040 2.4728539 6.249204 3.7400499 3.4524571 4.2276201 7.367024
#> 2 4.859829 4.1107374 9.461228 6.2482511 0.9190981 3.4362256 4.147537
#> 3 2.312462 1.0726071 5.431401 1.7927638 4.3289236 3.7928558 8.530197
#> 4 3.430782 0.9652047 5.799425 1.3827994 4.6922109 3.4668927 8.871686
#> 5 3.050016 4.6966600 1.777652 3.0837301 7.7705203 7.4582316 11.849276
#> 6 4.223277 1.9677985 8.179639 4.2359721 1.8414995 1.5255369 5.971752
#> 7 9.222104 7.7345226 13.727857 10.0025681 4.1824936 5.5421088 1.199729
#> 8 3.406177 5.9036860 1.858525 4.6164627 8.5009379 8.6095551 12.376703
#> 9 2.577735 0.6844318 6.005007 2.2511825 3.7710330 3.2589724 7.977684
#> 10 3.078184 1.0316205 5.504086 1.2395741 4.7343970 3.7026366 8.935149
#> 11 4.828071 2.1862991 8.568965 4.4007528 2.1335329 0.8255507 6.022996
#> 12 2.432839 2.0759815 4.342871 0.9877602 5.5198378 4.8326894 9.718041
#> 13 1.820053 1.4634525 5.655908 2.5243584 3.9091347 3.8633068 8.058047
#> 14 9.567989 7.3468146 13.700884 9.5266308 4.5379555 4.7012081 3.493031
#> 15 0.000000 3.2577156 4.712364 3.4205936 5.1178953 5.6155252 8.981925
#> 16 3.257716 0.0000000 6.413898 2.2682718 3.7311682 2.7628688 7.920166
#> 17 4.712364 6.4138978 0.000000 4.5659761 9.5466866 9.1748007 13.608764
#> 18 3.420594 2.2682718 4.565976 0.0000000 5.9684181 4.8424389 10.172259
#> 19 5.117895 3.7311682 9.546687 5.9684181 0.0000000 2.5768732 4.208423
#> 20 5.615525 2.7628688 9.174801 4.8424389 2.5768732 0.0000000 6.045392
#> 21 8.981925 7.9201661 13.608764 10.1722587 4.2084235 6.0453918 0.000000
#> 22 2.626623 0.8691300 6.365184 2.7156362 3.3244861 3.0326156 7.527211
#> 23 1.869928 2.0929857 6.303008 3.4983213 3.2894277 3.8749660 7.309744
#> 24 3.731193 5.3176287 1.102176 3.5450256 8.4615089 8.0799011 12.547451
#> 25 4.710792 1.4640217 7.380123 2.8556913 4.1142408 2.1611524 8.061060
#> 22 23 24 25
#> 1 1.6163378 0.3928893 5.2056598 3.871937
#> 2 3.5344049 3.1645151 8.4014445 4.745462
#> 3 1.0045267 1.7359228 4.3295406 2.441958
#> 4 1.6626284 2.7579152 4.7288798 1.600041
#> 5 4.5968346 4.5395927 0.6990053 5.769534
#> 6 1.8180925 2.4066472 7.0778846 2.311259
#> 7 7.4667432 7.4467083 12.6438963 7.658394
#> 8 5.6096273 5.2148671 1.6281312 7.130769
#> 9 0.4644977 1.5132792 4.9028539 2.147964
#> 10 1.5481021 2.5390085 4.4231833 1.941029
#> 11 2.2939206 3.0590062 7.4680474 2.045580
#> 12 2.1961930 2.7020560 3.2515546 3.128891
#> 13 0.8313913 0.9739679 4.5626017 2.927455
#> 14 7.3434237 7.7000532 12.5987267 6.836917
#> 15 2.6266230 1.8699285 3.7311931 4.710792
#> 16 0.8691300 2.0929857 5.3176287 1.464022
#> 17 6.3651836 6.3030075 1.1021756 7.380123
#> 18 2.7156362 3.4983213 3.5450256 2.855691
#> 19 3.3244861 3.2894277 8.4615089 4.114241
#> 20 3.0326156 3.8749660 8.0799011 2.161152
#> 21 7.5272112 7.3097438 12.5474512 8.061060
#> 22 0.0000000 1.2303288 5.2641634 2.261568
#> 23 1.2303288 0.0000000 5.2377081 3.481127
#> 24 5.2641634 5.2377081 0.0000000 6.319483
#> 25 2.2615680 3.4811270 6.3194831 0.000000