title: R - Finding closest neighboring point and number of neighbors within a given radius, coordinates lat-long
body: <p>I am trying to figure out how isolated certain points are within my data set. I am using two methods to determine isolation, the distance of the closest neighbor and the number of neighboring sites within a given radius. All my coordinates are in latitude and longitude</p>
  
  <p>This is what my data looks like: </p>
  
  <pre><code>    pond            lat         long        area    canopy  avg.depth   neighbor    n.lat   n.long  n.distance  n.area  n.canopy    n.depth n.avg.depth radius1500
      A10             41.95928    -72.14605   1500    66      60.61538462                                 
      AA006           41.96431    -72.121     250     0       57.77777778                                 
      Blacksmith      41.95508    -72.123803  361     77      71.3125                                 
      Borrow.Pit.1    41.95601    -72.15419   0       0       41.44444444                                 
      Borrow.Pit.2    41.95571    -72.15413   0       0       37.7                                    
      Borrow.Pit.3    41.95546    -72.15375   0       0       29.22222222                                 
      Boulder         41.918223   -72.14978   1392    98      43.53333333                                 
  </code></pre>
  
  <p>I want to put the name of the nearest neighboring pond in the column neighbor, its lat and long in n.lat and n.long, the distance between the two ponds in n.distance, and the area, canopy and avg.depth in each of the appropriate columns.</p>
  
  <p>Second, I want to put the number of ponds within 1500m of the target pond into radius1500.</p>
  
  <p>Does anyone know of a function or package that will help me calculate the distances/numbers that I want? If it's an issue, it won't be hard to enter the other data I need, but the nearest neighbor's name and distance, plus the number of ponds within 1500m is what I really need help with. </p>
  
  <p>Thank you.</p>