nearest | R Documentation |
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.
nearest(
nearest_df,
to_df,
nearest_lat = "lat",
nearest_long = "long",
to_lat = "lat",
to_long = "long"
)
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. |
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.
nearest(nearest_df = york_crime,
to_df = york)
# you can use the pipe as well
york_crime |> nearest(york)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.