I have a dataset with 4 columns:
start_lat 41.90687, 41.94367, 41.93259, 41.89076
start_lng -87.62622, -87.64895, -87.63643, -87.63170
end_lat 41.90672, 41.98404, 41.93650, 41.91831
end_lng -87.63483, -87.66027, -87.64754
I want to add a 5th column named distance and I use the following formula, but I get the following error:
trips_202007 <- trips_202007 %>%
rowwise()
mutate(distance = distm(c(trips_202007["start_lng"], trips_202007["start_lat"]), c(trips_202007["end_lng"], trips_202007["end_lat"]), fun=distHaversine))
Error in .pointsToMatrix(x) : 'list' object cannot be coerced to type 'double'
Is there a way to avoid the error?
Thank you very much for the advice.
This is the file I got after dput(trips_202007, file="trips_202007.txt"): https://drive.google.com/file/d/1lnXeNqIRCDad0WotgoUQhrfPg0AXApLr/view?usp=sharing