As written in the title I want to calculate the distance from all gas stations in my hometown to the two motorway accesses around here using the package osrm.
stations_ms contains Latitude & Longitude for the gas stations and highway_ms.df contains the lat & long for the motorway accesses.
Calculating the distance for just one row of my dataset is no problem, but I am not able to create a loop/function, which does it for every row.
Here is my code:
route4 <- osrmRoute(src = c(stations_ms$longitude[1], stations_ms$latitude[1]),
dst = highway_ms.df[1,],
overview = "FALSE")
for (i in 1:nrow(stations_ms)) {
route[i] <- osrmRoute(src = c(stations_ms$longitude[i], stations_ms$latitude[i]),
dst = highway_ms.df[1,],
overwiew = "FALSE")
}
```
Maybe someone can help me :)