spatial_link_index: Spatial index distance matrix

Description Usage Arguments Value Examples

View source: R/arepa.R

Description

Spatial index distance matrix

Usage

1
2
spatial_link_index(data1, lat1, lon1, id1, data2, lat2, lon2, id2,
  within = NULL, closest = FALSE)

Arguments

data1

Dataset 1

lat1

Latitude variable in dataset 1

lon1

Longitude variable in dataset 1

id1

Unique key in dataset 1

data2

Dataset 1

lat2

Latitude variable in dataset 2

lon2

Longitude variable in dataset 2

id2

Unique key in dataset 2

within

Link within kilometers

closest

Closest within Boolean (unique key is id2, so typically zip code)

Value

This function returns a data table of pairwise distances within kilometers with column names id1, id2 and Distance.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
years <- 2000:2002 # possible range 1990-2018
within_km <- 9.656 # 6 miles
parameter_code <- 81102 # for PM 10
##----- Get PM10 annual data and set unique Monitor key
# Download AQS data in Data_AQS/all.
# get_AQS_data_annual(years)
PM <- load_annual_average(years)
PM <- subset(PM, Parameter.Code == parameter_code)
##----- Zip codes
ZIP <- get_zip_codes()
##----- Spatial index to join monitors and Zip codes.  May take a couple of minutes
Link_PM_Zip_Index <- spatial_link_index(PM, "Latitude", "Longitude", "Monitor",
                                        ZIP, "Latitude.zip", "Longitude.zip", "zip",
                                        within = within_km) 

czigler/arepa documentation built on Oct. 2, 2020, 7:38 p.m.