title: R: applying a function on whole dataset to find points within a circle
body: <p>I have a difficulty with application of the data frame on my function in R. I have a data.frame with three columns ID of a point, its location on x axis and its location on y axis. All I need to do is to find for a given point IDs of points that lies in its neighborhood. I've made the function that shows whether the point lies within a circle where the center is a location of observed point and returns it's ID if true.</p>
  
  <p>Here is my code:      </p>
  
  <pre><code>point_id &lt;- locationdata$point_id
  x_loc &lt;- locationdata$x_loc
  y_loc &lt;- locationdata$y_loc
  
  locdata &lt;- data.frame(point_id, x_loc, y_loc)
  
  #radius set to1km
  incircle3 &lt;- function(x_loc, y_loc, center_x, center_y, pointid, r = 1000000){
  
          dx = (x_loc-center_x)
          dy = (y_loc-center_y)
  
  
          if (b &lt;- dx^2 + dy^2 &lt;= r^2){
                  print(shopid)}  ##else {print('')}
  
  }
  </code></pre>
  
  <p>Unfortunately I don't know how to apply this function on the whole data frame. So once I enter the locations of the observed point it would return me IDs of all points that lies in the neighborhood. Ideally I would need to find this relation for all the points automatically. So it would return me the points that lies in the neighborhood of each point from the dataset. Previously I have been inserting the center_x and center_y manually. </p>
  
  <p>Thank you very much for your advices in advance!</p>