Learn R Programming

gsClusterDetect (version 1.0.0)

county_distance_matrix: Get distance matrix for counties within a state

Description

Function returns a list of counties and a matrix with the distance between those counties. leverages a built in dataset (`counties`).

Usage

county_distance_matrix(
  st,
  unit = c("miles", "kilometers", "meters"),
  source = c("tigris", "rnssp")
)

Value

a named list of length two; first element (`loc_vec`) is a vector of locations and the second element (`distance_matrix`) is a square matrix containing the pairwise distance (in the given `unit`) between all locations.

Arguments

st

two-character string denoting a state, or "US". If "US", then this is equivalent to calling us_distance_matrix().

unit

string, one of "miles" (default), "kilometers", or "meters". Indicating the desired unit for the distances

source

string indicating either "tigris" (default) or "rnssp". Both are built-in datasets (i.e. are part of this package). The default ("tigris") uses county names and locations as found in tigris 2024. The "rnssp" option uses a package-stored version of the publicly available shape file for counties from Rnssp package at https://cdcgov.github.io/Rnssp/

Examples

Run this code
county_distance_matrix("MD", source = "tigris")
county_distance_matrix("WI", source = "rnssp", unit = "kilometers")

Run the code above in your browser using DataLab