# nearest: Find the nearest lat/long to another lat/long In njtierney/copertura: A Set of Tools For Solving The Maximal Covering Location Problem

## Description

This function finds the nearest lat/long pairs to another lat/long pair. So in the york building and york crime context, writing `nearest(york_crime,york)` reads as "find the nearest crime in york to each building in york, and returns a dataframe with every building in york, the nearest york_crime to each building, and the distance in metres between the two. Likewise, you could write `nearest(york, york_crime)`, and this would return the nearest building to every crime. `nearest` assumes that the names of the latitude and longitude are "lat" and "long", but you can provide these names.

## Usage

 ```1 2``` ```nearest(nearest_df, to_df, nearest_lat = "lat", nearest_long = "long", to_lat = "lat", to_long = "long") ```

## Arguments

 `nearest_df` a dataframe containing latitude and longitude `to_df` a dataframe containing latitude and longitude `nearest_lat` name of latitude in nearest_df `nearest_long` name of longitude in nearest_df `to_lat` name of latitude in to_df `to_long` name of longitude in to_df

## Value

dataframe of "to_df" along with the nearest "nearest_df" to each row, along with the distance between the two, and the nearest_id, the row position of the nearest_df closest to that row.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```library(maxcovr) nearest(nearest_df = york_crime, to_df = york) # you can use the pipe as well ## Not run: library(magrittr) york_crime %>% nearest(york) ## End(Not run) ```

njtierney/copertura documentation built on Aug. 10, 2018, 2:27 p.m.