facility_user_dist: facility_user_dist

Description Usage Arguments Value

View source: R/facility_user_dist.R

Description

Uses haversines formula to calculate the distance between lat/long co-ordinates of every facility and every user, returning a data_frame. You can think of "facilities" as something like mobile towers, police centres, or AED locations, and "users" as something like individual houses, crime locations, or heart attack locations. The motivating example for this function was finding the distance from Automatic Electronic Defibrillators (AEDs) to each Out of Hospital Cardiac Arrest (OHCA), where the locations for AEDs and OHCAs are in separate dataframes. Currently facifacility_user_dist makes the strict assumption that the facility and user dataframes have columns named aed_id, lat, and long, and ohca_id, lat, and long. This will be updated soon.

Usage

1
2
facility_user_dist(facility, user, coverage_distance = 100,
  nearest = "facility")

Arguments

facility

a dataframe containing columns named "lat", and "long".

user

a dataframe containing columns "lat", and "long".

coverage_distance

numeric indicating the coverage level for the facilities to be within in metres to a user. Default value is 100 metres.

nearest

character Can be "facility", "user", and "both". Defaults to "facility". When set to "facility", returns a dataframe where every row refers to every user, and the closest facility to each user. When set to "user", it returns a dataframe where every row is every facility, and the closest user to each facility. When set to "both", which will return every pairwise combination of distances. Be careful when default is "facility".

Value

a data frame containing the two datasets joined together with columns named facility_id, lat_facility, long_facility, user_id, lat_user, long_user, distance in meters between each the given facility and user in a row.


njtierney/maxcovr documentation built on Nov. 13, 2019, 6:38 p.m.