5
I have a vector origem
and a vector destino
with different locations in latitude and longitude.
For each location in origem
, I want to count how many places in destino
are located in a radius of up to 2km, and for that I made a function that calculates the distances distanciaEmKm(lat1, long1, lat2, long2)
.
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)
}
So I’d like to know if there’s another way and avoid that for
and make it already rotate to all lines of both vectors.
Oops, thanks again Falbel! In addition to the answer to the original problem, I found very interesting the idea of list-column. I’ve had problems where I had to run the code several times to get different information, but I never had the idea to store in list. Thanks!
– TheBiro