【发布时间】:2020-09-23 21:28:05
【问题描述】:
我有 2 个数据集,一个用于医院,另一个用于程序。每个数据集都有纬度和经度坐标。程序要么在医院内进行,要么在医院外进行,尽管如果在医院提供坐标,则不一定精确。我试图在每家医院周围形成一定大小的半径,并确定平均有多少手术点落在该半径内。因此,例如,如果我有 100 家医院和 3000 个程序,我想在所有医院周围形成一个半径,然后查看平均有多少家医院落入该指定半径内。我的初始代码如下,但我知道这可以更快地完成。用 R 编码。谢谢!
for(i in 1:NROW(hospitals)){
hospital <- hospitals[i,]
radius <- .016
# find all the procedures that lie in the .016 sized radius from this hospital
hospital$latitude_low <- hospital$lat - radius
hospital$longitude_low <- hospital$long - radius
hospital$latitude_high <- hospital$lat + radius
hospital$longitude_high <- hospital$long + radius
in_rad <- procedures[(procedures$long >= hospital$longitude_low & procedures$long <=
hospital$longitude_high & procedures$lat <= hospital$latitude_high & procedures$lat >=
hospital$latitude_low),]
num <- NROW(in_rad)
hospitals[i,]$number_of_procedures <- num
}
【问题讨论】:
-
这里的答案可能会有所帮助:stackoverflow.com/q/21977720/12265198。我建议使用
fields包函数rdist.earth。您可以得到两个 lon/lat 坐标矩阵之间的公里或英里距离。
标签: r geospatial raster geosphere