0

I have a data frame of the form

lon1 lat1 lon2 lat2
... ... ... ...
... ... ... ...

representing coordinates of pairs of points. How do I do to calculate the geodesic distance between the pairs in a new column? There is the package geosphere which can do this for pairs of points of the form distm(c(lon1, lat1), c(lon2, lat2)). Is there a way to apply this directly to the columns?

zx8754
  • 52,746
  • 12
  • 114
  • 209
mathology
  • 147
  • 4
  • See linked post, it is for data.table object, but the solution could be used for data.frames, too. – zx8754 Mar 30 '21 at 11:50

1 Answers1

0

With some toy data

library(geosphere)

dat=matrix(rnorm(3*4),3,4)

distGeo(dat[,1:2],dat[,3:4])

[1] 249363.2 134563.1 146278.5
user2974951
  • 9,535
  • 1
  • 17
  • 24