I have a origem
vector and a destino
vector with several locations in latitude and longitude.
For each location in origem
, I want to count how many places in destino
are located within a radius of up to 2km, so I did a function that calculates the distanciaEmKm(lat1, long1, lat2, long2)
distances.
I then solved the problem as follows:
for (i in 1:nrow(destino)) {
dists <- mapply(distanceLatLongKm, origem$LAT[i], origem$LONG[i], destino$LAT, destino$LONG)
origem$ATE_2KM[i] <- sum(dists <= 2)
}
Then I would like to know if there is another way and avoid this for
and make it already run to all lines of both vectors.