Below dataframe contains the information about the lat, long , state and city. I want to find the three nearest cities for every city given in the dataframe. For example, from the below dataframe, Oklahoma city and Colarado SPringd nearest to Albuquerque, So three nearest city to Albuquerque should be saved in other dataframe named nearest_AL(I don't know how to get this result, that'y I tried to gave an idea by creating a data frame).
dataframe<-data.frame(long=c("-106.61291","-81.97224","-84.42770","-72.68604","-97.60056","-104.70261"),
lat=c("35.04333","33.37378","33.64073","41.93887","35.39305","38.80171"),
state=c("NM","GA","GA","TX","OK","CO"),
city=c("Albuquerque","Augusta","Atlanta","Windsor Locks","Oklahoma City","Colarado Springs")
)
nearest_Al<-data.frame(long=c("-97.60056","-104.70261"),
lat=c("35.39305","38.80171"),
state=c("OK","CO"),
city=c("Oklahoma City","Colarado Springs")
)
This same thing I have to perform on the dataframe which contains rows 500k and around 100 locations.
Thanks in advance!