This function builds the pairwise distance matrix from vectors of XY coordinates and associated names.

get_distance_matrix(x, y, id)

Arguments

x

vector giving X coordinates

y

vector giving Y coordinates

id

vector of names for each location

Value

a named matrix of pairwise distances among locations

See also

Other data synthesis: get_crossdist(), get_mob_matrix(), get_stay_data()

Author

John Giles

Examples

n <- 5 xy <- data.frame(x=rnorm(n, -90, 1), y=rnorm(n, 30, 1), id=LETTERS[1:n]) D <- get_distance_matrix(x=xy[,1], y=xy[,2], id=xy[,3]) # From simulated travel data xy <- get_unique_coords(travel_data_sim)
#> Added missing unique location names.
D <- get_distance_matrix(x=xy[,1], y=xy[,2], id=xy[,3]) D*111.35 # decimal degrees to km
#> destination #> origin A_B_A A_B_B A_B_C A_B_D A_B_E A_B_F A_B_G #> A_B_A 0.00000 236.22609 151.063238 493.08241 139.02433 195.41698 253.90469 #> A_B_B 236.22609 0.00000 85.843571 346.25626 99.05488 74.38032 138.09683 #> A_B_C 151.06324 85.84357 0.000000 396.33982 26.41282 59.72543 158.20565 #> A_B_D 493.08241 346.25626 396.339821 0.00000 385.29829 417.99757 243.38501 #> A_B_E 139.02433 99.05488 26.412818 385.29829 0.00000 85.90392 143.46924 #> A_B_F 195.41698 74.38032 59.725427 417.99757 85.90392 0.00000 194.17535 #> A_B_G 253.90469 138.09683 158.205648 243.38501 143.46924 194.17535 0.00000 #> A_B_H 432.62167 296.24687 340.219985 60.81970 327.76453 365.84915 184.77599 #> A_B_I 362.21610 150.67043 225.545131 216.43288 226.73470 224.72505 138.08088 #> A_B_J 329.39711 141.11697 203.116882 206.08448 199.33119 214.47513 92.40469 #> A_B_K 398.99034 286.04687 319.156084 102.56554 303.85616 351.33310 160.96922 #> A_B_L 152.47967 208.34127 159.991491 354.39150 133.57910 219.12406 138.80304 #> A_B_M 101.49967 251.29563 171.720651 559.11501 175.67118 186.57003 315.77205 #> A_B_N 474.93744 312.79149 368.680769 43.28104 359.85541 385.83963 221.61440 #> A_B_O 365.12664 243.10841 277.969870 128.32361 263.70147 308.72626 120.25410 #> A_B_Q 167.78331 243.17988 179.939412 576.20121 193.93370 169.80309 336.99091 #> A_B_R 286.42242 70.29810 144.707352 279.16051 148.35221 144.66875 106.24550 #> A_B_S 126.44255 174.75554 118.528181 367.74870 92.19799 178.09184 134.58902 #> A_B_T 197.02888 56.61497 51.329842 398.40936 75.69554 19.83853 174.70115 #> A_B_U 155.57374 80.94208 5.579885 391.15161 26.51461 59.58134 153.55446 #> A_B_V 266.68778 254.39841 224.113425 600.65454 246.61595 184.51877 377.38283 #> A_B_W 76.45567 175.01731 97.666498 417.72593 76.64907 154.38566 177.49406 #> A_B_Y 257.21027 27.49950 109.157225 321.17999 118.35219 101.75363 125.17383 #> A_B_Z 316.61422 136.63167 193.692233 209.64723 188.43841 208.72785 77.37274 #> destination #> origin A_B_H A_B_I A_B_J A_B_K A_B_L A_B_M A_B_N #> A_B_A 432.62167 362.21610 329.39711 398.99034 152.47967 101.4997 474.93744 #> A_B_B 296.24687 150.67043 141.11697 286.04687 208.34127 251.2956 312.79149 #> A_B_C 340.21998 225.54513 203.11688 319.15608 159.99149 171.7207 368.68077 #> A_B_D 60.81970 216.43288 206.08448 102.56554 354.39150 559.1150 43.28104 #> A_B_E 327.76453 226.73470 199.33119 303.85616 133.57910 175.6712 359.85541 #> A_B_F 365.84915 224.72505 214.47513 351.33310 219.12406 186.5700 385.83963 #> A_B_G 184.77599 138.08088 92.40469 160.96922 138.80304 315.7720 221.61440 #> A_B_H 0.00000 181.23864 160.27512 46.63472 293.66330 500.3910 60.52580 #> A_B_I 181.23864 0.00000 47.34630 192.69826 274.09556 397.0841 176.69922 #> A_B_J 160.27512 47.34630 0.00000 161.26285 230.37167 374.0016 171.67884 #> A_B_K 46.63472 192.69826 161.26285 0.00000 255.09768 472.4225 106.97637 #> A_B_L 293.66330 274.09556 230.37167 255.09768 0.00000 243.8346 343.19724 #> A_B_M 500.39103 397.08409 374.00159 472.42247 243.83463 0.0000 535.13616 #> A_B_N 60.52580 176.69922 171.67884 106.97637 343.19724 535.1362 0.00000 #> A_B_O 67.58146 156.50664 120.97617 42.93890 226.82002 434.5072 118.05116 #> A_B_Q 520.11213 393.82617 379.08528 497.71962 292.75100 74.2300 547.71141 #> A_B_R 232.40417 81.60705 73.09231 228.43182 220.32481 315.8347 244.07998 #> A_B_S 307.07147 260.63694 220.55767 272.59373 42.72724 209.1119 351.76440 #> A_B_T 346.06984 207.27564 195.38951 331.51931 206.67423 197.9304 366.53897 #> A_B_U 335.17558 219.98093 197.57898 314.45609 159.57214 177.3001 363.33286 #> A_B_V 549.86495 397.15172 395.14336 535.78551 368.73269 181.0732 566.68608 #> A_B_W 357.50873 288.86895 254.14487 325.41995 93.83334 152.5300 398.73724 #> A_B_Y 272.64313 123.17101 115.30805 265.06047 213.97012 277.4975 286.84614 #> A_B_Z 160.72993 61.82174 15.03364 157.36413 215.44995 363.7167 177.31043 #> destination #> origin A_B_O A_B_Q A_B_R A_B_S A_B_T A_B_U A_B_V #> A_B_A 365.12664 167.7833 286.42242 126.44255 197.02888 155.573735 266.6878 #> A_B_B 243.10841 243.1799 70.29810 174.75554 56.61497 80.942083 254.3984 #> A_B_C 277.96987 179.9394 144.70735 118.52818 51.32984 5.579885 224.1134 #> A_B_D 128.32361 576.2012 279.16051 367.74870 398.40936 391.151606 600.6545 #> A_B_E 263.70147 193.9337 148.35221 92.19799 75.69554 26.514610 246.6159 #> A_B_F 308.72626 169.8031 144.66875 178.09184 19.83853 59.581337 184.5188 #> A_B_G 120.25410 336.9909 106.24550 134.58902 174.70115 153.554460 377.3828 #> A_B_H 67.58146 520.1121 232.40417 307.07147 346.06984 335.175578 549.8650 #> A_B_I 156.50664 393.8262 81.60705 260.63694 207.27564 219.980931 397.1517 #> A_B_J 120.97617 379.0853 73.09231 220.55767 195.38951 197.578983 395.1434 #> A_B_K 42.93890 497.7196 228.43182 272.59373 331.51931 314.456088 535.7855 #> A_B_L 226.82002 292.7510 220.32481 42.72724 206.67423 159.572140 368.7327 #> A_B_M 434.50724 74.2300 315.83472 209.11190 197.93044 177.300079 181.0732 #> A_B_N 118.05116 547.7114 244.07998 351.76440 366.53897 363.332862 566.6861 #> A_B_O 0.00000 457.2007 186.11443 239.49124 288.89882 273.152201 493.2285 #> A_B_Q 457.20071 0.0000 312.77805 253.20516 186.56494 185.070594 107.3743 #> A_B_R 186.11443 312.7780 0.00000 197.57583 126.51540 139.181009 322.6592 #> A_B_S 239.49124 253.2052 197.57583 0.00000 166.77014 118.560760 326.4022 #> A_B_T 288.89882 186.5649 126.51540 166.77014 0.00000 49.432113 204.3552 #> A_B_U 273.15220 185.0706 139.18101 118.56076 49.43211 0.000000 227.6148 #> A_B_V 493.22847 107.3743 322.65922 326.40218 204.35518 227.614761 0.0000 #> A_B_W 290.21222 198.9652 216.14914 56.58294 148.89528 100.346735 279.0238 #> A_B_Y 222.21503 270.6716 43.20926 184.27206 84.10913 103.897361 279.8566 #> A_B_Z 115.74887 371.1734 71.94669 206.25672 189.31630 188.205269 391.0228 #> destination #> origin A_B_W A_B_Y A_B_Z #> A_B_A 76.45567 257.21027 316.61422 #> A_B_B 175.01731 27.49950 136.63167 #> A_B_C 97.66650 109.15723 193.69223 #> A_B_D 417.72593 321.17999 209.64723 #> A_B_E 76.64907 118.35219 188.43841 #> A_B_F 154.38566 101.75363 208.72785 #> A_B_G 177.49406 125.17383 77.37274 #> A_B_H 357.50873 272.64313 160.72993 #> A_B_I 288.86895 123.17101 61.82174 #> A_B_J 254.14487 115.30805 15.03364 #> A_B_K 325.41995 265.06047 157.36413 #> A_B_L 93.83334 213.97012 215.44995 #> A_B_M 152.53000 277.49751 363.71673 #> A_B_N 398.73724 286.84614 177.31043 #> A_B_O 290.21222 222.21503 115.74887 #> A_B_Q 198.96521 270.67164 371.17341 #> A_B_R 216.14914 43.20926 71.94669 #> A_B_S 56.58294 184.27206 206.25672 #> A_B_T 148.89528 84.10913 189.31630 #> A_B_U 100.34673 103.89736 188.20527 #> A_B_V 279.02383 279.85664 391.02276 #> A_B_W 0.00000 192.00386 241.02483 #> A_B_Y 192.00386 0.00000 112.09148 #> A_B_Z 241.02483 112.09148 0.00000