title: Calculating number of points within a certain radius
body: <p>Given a data frame with latitudes and longitudes I want to add a column that simply contains the count of other points (of the same data frame) that are within a certain radius e.g. within 10 km of that specific point.</p>
  
  <p>Example data:</p>
  
  <pre><code>set.seed(1)
  radius&lt;-10
  lat&lt;-runif(10,-90,90)
  long&lt;-runif(10,-180,180)
  id&lt;-1:10
  dat&lt;-cbind(id,lat,long)
  
        id       lat         long
   [1,]  1 -42.20844 -105.8491530
   [2,]  2 -23.01770 -116.4395691
   [3,]  3  13.11361   67.3282248
   [4,]  4  73.47740  -41.7226614
   [5,]  5 -53.69725   97.1429112
   [6,]  6  71.71014   -0.8282728
   [7,]  7  80.04155   78.3426630
   [8,]  8  28.94360  177.0861941
   [9,]  9  23.24053  -43.1873354
  [10,] 10 -78.87847   99.8802797
  </code></pre>
  
  <p>Now given the radius variable I want a new column say "X" that for each point only contains the number of other points that are within "radius". I do not care about which points these are.</p>
  
  <p>While this <a href="https://stackoverflow.com/questions/21977720/r-finding-closest-neighboring-point-and-number-of-neighbors-within-a-given-rad?rq=1">R - Finding closest neighboring point and number of neighbors within a given radius, coordinates lat-long</a> topic and answer get close it does not solve the specific question of the simple count. This question is different as I need the counts of all points within the radius and not the points</p>