Computing Euclidean distances between subsequent positions

▼魔方 西西 提交于 2019-12-01 23:05:14
blindjesse

Something like

sqrt(diff(dff$X)^2 + diff(dff$Y)^2)

should work. The key here is the diff function, which gives differences between consecutive items in a vector

Another approach, just for fun:

sqrt(apply(apply(dff[,c("X","Y")], 2, diff)^2, 1, sum))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!