get_distance_matrix: Build distance matrix from XY coordinates

Description Usage Arguments Value Author(s) See Also Examples

View source: R/utils.R

Description

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

Usage

1

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

Author(s)

John Giles

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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)
D <- get_distance_matrix(x=xy[,1],
                         y=xy[,2],
                         id=xy[,3])

D*111.35 # decimal degrees to km

COVID-19-Mobility-Data-Network/mobility documentation built on Nov. 22, 2021, 12:17 a.m.