I need to find the density of each point within a data set using k-NN density estimation algorithm. I understand the basic approach used for calculation as shown in the screenshot below. Complete slides at [link]
I want to know is there any library within R which provides functions to calculate K-NN density estimation. Although there are some relevant questions on the same topic on stackoverflow, but none of them is properly answered.
Note: I found this question relevant, but again the answers do not work.
Although I did not find any R package which calculates density at a point. But, I followed these steps to calculate density at each point:
Note: In R, neighbors are sorted according to distance using order( ) function