我需要确定位于特定试金体内的一组微米坐标的一小部分。 这一试金字被定义为双方距离协调制度的边缘相当遥远的地区(在这种情况下,协调制度受大约(-50, - 20),(-50, 20),(50,20),(50,20),(50,-20)。 此外,我希望能够测试与边缘不同距离的试金星结果。 我的方法如下:
# set initial limits to the coordinate system
lim.xleft = -50
lim.xright = 50
lim.ybottom = -20
lim.ytop = 20
frac.near.edge <- function(coord.pairs, tolerance){
# set the coordinates of the rectangle of interest
exclude.xleft = lim.xleft + tolerance
exclude.xright = lim.xright - tolerance
exclude.ybottom = lim.ybottom + tolerance
exclude.ytop = lim.ytop - tolerance
out <- vector()
# loop through the pairs testing whether the point is inside the rectangle or outside
for(i in 1:nrow(coord.pairs)){
if(coord.pairs[i, 1] > exclude.xleft & coord.pairs[i, 1] < exclude.xright & coord.pairs[i, 2] > exclude.ybottom & coord.pairs[i, 2] < exclude.ytop){
out[i] <- "in"
} else {
out[i] <- "out"
}
}
# return how many points were inside the rectangle and how many were outside
return(table(out))
}
# try it out on something much bigger!
foo <- data.fram(x = runif(100), y = runif(100))
system.time(frac.near.edge(foo, tolerance = 5))
大型数据集(按10°5×y pairs的顺序排列的地雷)的浓度为very。 我如何能够加快这一进程? 环形周围的方法?