I have two dataframes, "a" and "b". They both have gps data, but "a" has 1000 rows and "b" has 5 rows. I am comparing distances with the haversine formula, but I want to apply the function so that each row of "a" is compared to every row of "b". I should end up with 5000 results.
This is what I have so far, but it only gives me 1000 results:
library(geosphere)
for(i in 1:nrow(a)){
distHaversine(a[,c(11,9)],b[,c(4,2)])
}
Thanks in advance for any assistance.
EDIT
I found a much better solution to my problem that cuts down on both code and computing time:
library(geosphere)
result <- distm(a[ , c(11, 9)], b[ , c(4, 2)], fun = distHaversine)