This question already has an answer here:
- Clustering spatial data in R? [closed] 7 answers
I have some points that I need to divide into groups based on clusters of points:
x <- c(-1.482156, -1.482318, -1.482129, -1.482880, -1.485735, -1.485770, -1.485913, -1.484275, -1.485866) y <- c(54.90083, 54.90078, 54.90077, 54.90011, 54.89936, 54.89935, 54.89935, 54.89879, 54.89902) library(sp) xy <- SpatialPoints(matrix(c(x,y), ncol=2)) proj4string(xy) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") xyTransformed <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) plot(xyTransformed)
Each group should be defined using this rule: all points in the group should be within 40m of each other.
Based on the points in code above, I believe I should end up with 3-4 groups.
Does anybody know how to do this in R?