I have a problem in the application of data frames on my function. In it, three column IDs of one point, on the x-axis Its location and its location on the Y axis, I have to do just that I will have to find the given point id of the points given in the neighboring area. I have shown the function which states that the point is located within a circle where the center is the location of a point and if it is true, then it returns the ID.
Here's my code:
point_id Many thanks for your advice!
You can deal with this with R district
with the function:
# set random seed and some dummy data set.seed (101) Create dummy & lt; - data.frame (ID = 1: 100, x = Ranif (100), y = Rinif (100)) gt; head (Dummy) ID xy 1 1 0,37219838 012501937 2 2 0,04382482 0,02332669 3 3 0, 70968402 0,39186128 4 4 0,65769040 0,85959857 5 5 0,24985572 0,71833452 6 6 0,30005483 0,33939503
dist Call> function which A dist
object returns the default distance metric that you have code in your question is euclidean
dists & lt; - District (Dummy [, 2: 3]).
Returns the index for each ID that is more loop than the distance matrix and that is within some constant distance:
neighbors & lt; - Applicable (as.matrix (dists), 1, function (x) which (x <0.33)) gt; Neighbors [1]] 1 6 7 8 1 9 23 30 32 33 34 42 44 46 51 55 87 88 91 94 99
Here is an amendment to handle the unstable ID: < / P>
set.seed (101) dummy & lt; - data.frame (id = sample (1: 100, 100), x = runoff (100), y = reinforced (100)) gt; Head (dummy) ID xy 1 38 0.12501937 0.60567568 2 5 0.02332669 0.56259740 3 70 0.39186128 0.27685556 4 64 0.85959857 0.22614243 5 24 0.71833452 0.98355758 6 29 0.33939503 0.09838715 Dists (Dimi [2: 3]) neighbors & lt; - Applicable (As.matrix (dists), 1, function (x) {dummy $ id [which (x <- 0.33)} name (neighbors) <- dummy $ id & gt; neighbors [['' ']] [1] 38 5 55 80 63 76 17 71 47 11 88 13 41 21 36 31 73 61 99 59 39 89 94 12 18 3
No comments:
Post a Comment