I'm just starting to learn R but would like project done sooner rather than later. It's rather simple: I have an X column and a Y column consisting of X coordinates and Y coordinates. (Working in the NAD27 coordinate system). Going from the first coordinate, I'd like to find the nearest point within the data set and then move onto the next coordinate and find it's nearest point within the same data set. Ideally, it would go through each point and determine the closest point.
point x y
1 1601774 14544454
2 1616574 14579422
3 1608698 14572922
4 1602948 14572990
5 1607355 14573871
6 1615336 14578178
7 1603398 14574495
8 1605153 14570727
9 1606758 14573845
10 1606655 14570953
sp::spDists
orrgeos::gDistance
ought to help, but you'll need to try some things first (folks are not just going to write code) – Juliannejulianods <- as.matrix(dist(dat, diag=TRUE, upper=TRUE)); diag(ds) <- Inf; apply(ds, 1, which.min)
. But there are probably cleverer ways. – Chemnitzsqrt(rowSums(sweep(mydata[-i,],MARGIN=1,FUN="-",mydata[i,])^2))
gets you all of the distances from pointi
to all other points ... – Ogham