Calculating number of points within a certain radius [duplicate]

江枫思渺然 提交于 2019-12-02 12:10:15
Sandipan Dey

Try this:

library(geosphere)
cbind(dat, X=rowSums(distm (dat[,3:2], 
       fun = distHaversine) / 1000 <= 10000)) # number of points within distance 10000 km

      id       lat         long X
 [1,]  1 -42.20844 -105.8491530 5
 [2,]  2 -23.01770 -116.4395691 5
 [3,]  3  13.11361   67.3282248 5
 [4,]  4  73.47740  -41.7226614 6
 [5,]  5 -53.69725   97.1429112 4
 [6,]  6  71.71014   -0.8282728 6
 [7,]  7  80.04155   78.3426630 6
 [8,]  8  28.94360  177.0861941 5
 [9,]  9  23.24053  -43.1873354 6
[10,] 10 -78.87847   99.8802797 4
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!