title: Extract buffer from a raster in R
body: <p>I am beginner in R and spatial analysis. I have a raster where the cells of habitat polygons are equal to 1.</p>
  
  <pre><code> img &lt;- readPNG("Paysage.png")
   map &lt;- raster(img[,,2],xmn=0, xmx=999, ymn=0, ymx=999)
   projection(map) &lt;- "+proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
   map[] &lt;- polygons[,c("id_polygon")] 
   map[ map &gt; 0] &lt;- 1
  </code></pre>
  
  <p>From this raster, how can I build, for each polygon, a raster in which all polygon cells that are situated in a buffer of 1 km around a given polygon are equal to 1 and all other matrix cells are equal to 0. </p>
  
  <p>Thanks very much for your help.</p>