You can use applywith the function gdistfrom the package Imap:
library(Imap)
df = data.frame(id=c(124, 537, 891),
value=c(50.4, 34.2, 42.0),
lat1=c(-13.2423, -13.2434, -13.2445),
lng1=c(-46.2342, -46.2331, -46.2389),
lat2=c(-13.2423, -13.2423, -13.2423),
lng2=c(-46.2342, -46.2342, -46.2342))
df$dist = apply(df, 1, function(x) gdist(x["lng1"], x["lat1"],
x["lng2"], x["lat2"], units="m"))
df
source
share