% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nearest.R
\name{nearest}
\alias{nearest}
\title{Find the nearest lat/long to another lat/long}
\usage{
nearest(nearest_df, to_df, nearest_lat = "lat", nearest_long = "long",
  to_lat = "lat", to_long = "long")
}
\arguments{
\item{nearest_df}{a dataframe containing latitude and longitude}

\item{to_df}{a dataframe containing latitude and longitude}

\item{nearest_lat}{name of latitude in nearest_df}

\item{nearest_long}{name of longitude in nearest_df}

\item{to_lat}{name of latitude in to_df}

\item{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.
}
\description{
This function finds the nearest lat/long pairs to another lat/long pair.
So in the york building and york crime context, writing
\code{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 \code{nearest(york, york_crime)}, and this
would return the nearest building to every crime. \code{nearest} assumes that
the names of the latitude and longitude are "lat" and "long", but you can
provide these names.
}
\examples{

library(maxcovr)

nearest(nearest_df = york_crime,
        to_df = york)

# you can use the pipe as well

\dontrun{

library(magrittr)
york_crime \%>\% nearest(york)

}

}
