title: Create buffer around spatial data in R
body: <p>I have a spatial dataset of shopping centers that I would like to create buffers around in R.</p>
  
  <p>I think these packages will be useful:</p>
  
  <pre><code>require(maptools)
  require(geosphere) 
  </code></pre>
  
  <p>I was able to do so for a set of coordinates, but not for spatial data. The code looks like this:</p>
  
  <pre><code>coordinates(locs) &lt;- c("Longitude", "Latitude")  # set spatial  coordinates
  fivekm &lt;- cbind(coordinates(locs), X=rowSums(distm (coordinates(locs)[,1:2], fun = distHaversine) / 1000 &lt;= 5)) # number of points within 5 km
  </code></pre>
  
  <p>But I don't know what function/package to use for a set of polygons. Can someone please advise on the function (or code) and I will go from there?</p>
  
  <p>Thanks!</p>