나는 여러 가지 해답을 이미 살펴 봤지만 문제에 적용하지 못했습니다. 참조 :별도의 df에서 위치 간 거리를 계산하는 방법 R
Calculating the distance between points in different data frames
Calculating number of points within a certain radius
find locations within certain lat/lon distance in r
find number of points within a radius in R using lon and lat coordinates
Identify points within specified distance in R
내가 DF loc
및 stop
있습니다. 각 stop
에 대해 loc
까지 거리를 찾고 싶습니다.
내 위치
loc <- data.frame(station = c('Baker Street','Bank'),
lat = c(51.522236,51.5134047),
lng = c(-0.157080, -0.08905843),
postcode = c('NW1','EC3V')
)
내 내가 이런 걸 원하는 최종 결과
stop <- data.frame(station = c('Angel','Barbican','Barons Court','Bayswater'),
lat = c(51.53253,51.520865,51.490281,51.51224),
lng = c(-0.10579,-0.097758,-0.214340,-0.187569),
postcode = c('EC1V','EC1A', 'W14', 'W2'))
를 중지 :
df <- data.frame(loc = c('Baker Street','Bank','Baker Street','Bank','Baker Street','Bank','Baker Street','Bank'),
stop = c('Angel','Barbican','Barons Court','Bayswater','Angel','Barbican','Barons Court','Bayswater'),
dist = c('x','x','x','x','x','x','x','x'),
lat = c(51.53253,51.520865,51.490281,51.51224,51.53253,51.520865,51.490281,51.51224),
lng = c(-0.10579,-0.097758,-0.214340,-0.187569,-0.10579,-0.097758,-0.214340,-0.187569),
postcode = c('EC1V','EC1A', 'W14', 'W2','EC1V','EC1A', 'W14', 'W2')
)
내 데이터 세트가 상대적으로 큰을 내가 찾고 있어요 이 문제를 해결하는 효율적인 방법입니다.
달성 방법에 대한 아이디어가 있으십니까?
질문을 올바르게 읽지는 못했지만 loc 데이터 프레임의 각 지점에서 중지 데이터 프레임의 각 지점 사이의 거리를 찾으려고합니까? – Awhstin
@Awhstin 예 ... 정확하게 'stop'에서 'loc'까지의 각 거리 – Davis
부수적으로, 저는 [어제 질문에 답변했습니다] (http://stackoverflow.com/a/40898595/496488) 'circle'을'circle'으로,'stop'을'dat'으로 대체하고 각 데이터 프레임에서 유지하고자하는 열을 계속 전달할 경우 여기에서 작동합니다. (질문은 중복되지 않지만 답변은 비슷합니다.) – eipi10