nearest: Find the nearest lat/long to another lat/long

View source: R/nearest.R

nearestR Documentation

Find the nearest lat/long to another lat/long

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

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


nearest(nearest_df = york_crime,
        to_df = york)

# you can use the pipe as well

york_crime |> nearest(york)


njtierney/maxcovr documentation built on Nov. 27, 2024, 7:51 a.m.