I'm trying to add a "distance" column to a huge (near 6 million rows) dataframe with coordinate information as start_lng
, start_lat
, end_lng
, end_lat
columns.
I have tried the following:
trips$distance <- distm(c(trips$start_lng, trips$start_lat), c(trips$end_lng, trips$end_lat), fun = distHaversine)`
to which I get:
"Error in .pointsToMatrix(x) : Wrong length for a vector, should be 2"
I checked the answers in here and the solution should be:
trips %>%
rowwise() %>%
mutate(distance = distHaversine(c(trips$start_lng, trips$start_lat), c(trips$end_lng, trips$end_lat)))
but I still get the same error: "base::stop("Wrong length for a vector, should be 2")"
I have also tried using cbind()
instead of c()
but "cannot allocate vector of size 123096.7 Gb"