Dear community,
I'm looking for a fast way to find the point with the most neighbors in a cloud of points within a given search radius.
I.e. is there a function that would be able to find the red point in the example below:
df <- crossing(x = seq(-1,1, length.out = 25), y = seq(-1,1, length.out = 25)) %>%
filter(sqrt(x^2 + y^2) <= 0.9) %>%
filter(sqrt((x+0.3)^2 + y^2) >= 0.4)
df %>%
ggplot(aes(x = x, y = y))+
geom_point(alpha = 0.5)+
geom_point(x = .5, y = 0, size = 60, shape = 1, colour = 'red')+
geom_point(x = .5, y = 0, colour = 'red')
And could this function generalize to N-dimensional cases?
Any help would be appreaciated.
Thanks
/Jannik