I have a dataframe of locations with their longitude and latitude, it looks something like:
set.seed(211)
latitude <-runif(5000, min=50, max=55)
longitude <- runif(5000, min=-2, max=0)
location_id <- seq(1,5000)
reprex <- data.frame(location_id, latitude, longitude)
For each location_id, I need to count the number of other locations within the list that are within 10 miles (~16000 metres) of that location.
I was thinking of using geosphere::distGeo() for this within some sort of for loop (or perhaps an apply function), but I just cannot work out how to code it so that it compares every other item in the list with the current item and counts how many are within a certain threshold, records that value and then moves on to the next row.
Does anyone know how to write this?