简体   繁体   中英

Proximity Analysis in R

I have a set of GPS coordinates in R that I want to treat as an "exposure" for another set of GPS coordinates corresponding to patients of interest. How do I do proximity analysis in R to separate patients into two groups: those within x meters of an exposure coordinate and those further away?

I think something like this should work:

library(sp)
exp <- data.frame(lat= 40.741895,long = -73.989308)
patients <- data.frame(lat = rnorm(10,exp$lat,0.1),long = rnorm(10,exp$long,0.1))
coordinates(patients) <- ~ long + lat
coordinates(exp) <- ~ long + lat
d <- spDistsN1(coordinates(patients),coordinates(exp),longlat = TRUE)

Strongly inspired from: Calculate distance from GPS data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM