I'm sure this is quite basic, but I just couldn't find anything appropriate: I am looking for a function that applies another function to variables of a SpatialPointsDataFrame, but only for locations that are the nearest neighbors of a specified location.
Alternatively, how can I subset a SpatialPointsDataFrame by distance to a given location?
For example, in the meuse data set (gstat package) I would like to calculate mean, variance and quantiles of zinc concentration for the 20 closest locations that are at most 0.1km away from location x=179997, y=331662.
I found the function applynbd() in the spatstat package, but it applies the given function to all points in the data frame insteat of a single one. Moreover, only a number of nearest neighbors OR a distance (max. radius) can be specified instead of both.