title: Aggregating raster data at coarser resolution
body: <p>I have a dataset that is 0.25 * 0.25 degree grid resolution</p>
  
  <pre><code>lon &lt;- c(-53.615449969, -53.365449969, -53.115449969, -53.365449969, 
       -53.115449969, -52.865449969, -53.365449969, -53.115449969, -52.865449969, 
       -52.615449969, -53.365449969, -53.115449969, -52.865449969, -52.615449969, 
       -52.365449969, -53.365449969, -53.115449969, -52.865449969, -52.615449969, 
       -52.365449969, -53.615449969, -53.365449969, -53.115449969, -52.865449969, 
       -52.615449969, -52.365449969, -52.115449969, -53.865449969, -53.615449969, 
       -53.365449969, -53.115449969, -52.865449969, -52.615449969, -52.365449969, 
       -52.115449969, -51.865449969, -54.365449969, -54.115449969, -53.865449969, 
       -53.615449969, -53.365449969, -53.115449969, -52.865449969, -52.615449969, 
       -52.365449969, -52.115449969, -51.865449969, -51.615449969, -54.615449969, 
       -54.365449969, -54.115449969, -53.865449969, -53.615449969, -53.365449969, 
       -53.115449969, -52.865449969, -52.615449969, -52.365449969, -52.115449969, 
       -51.615449969)
  
  
  lat &lt;- c(-33.627081271, -33.627081271, -33.627081271, -33.377081271, 
       -33.377081271, -33.377081271, -33.127081271, -33.127081271, -33.127081271, 
       -33.127081271, -32.877081271, -32.877081271, -32.877081271, -32.877081271, 
       -32.877081271, -32.627081271, -32.627081271, -32.627081271, -32.627081271, 
       -32.627081271, -32.377081271, -32.377081271, -32.377081271, -32.377081271, 
       -32.377081271, -32.377081271, -32.377081271, -32.127081271, -32.127081271, 
       -32.127081271, -32.127081271, -32.127081271, -32.127081271, -32.127081271, 
       -32.127081271, -32.127081271, -31.877081271, -31.877081271, -31.877081271, 
       -31.877081271, -31.877081271, -31.877081271, -31.877081271, -31.877081271, 
       -31.877081271, -31.877081271, -31.877081271, -31.877081271, -31.627081271, 
       -31.627081271, -31.627081271, -31.627081271, -31.627081271, -31.627081271, 
       -31.627081271, -31.627081271, -31.627081271, -31.627081271, -31.627081271, 
      -31.627081271)
  
   df &lt;- as.data.frame(cbind(lon, lat))
   df$ID &lt;- 1:nrow(df)
   coordinates(df) &lt;- c(1,2)
  
   library(raster)
   elev &lt;- getData('alt', country='BRA')
  
   plot(elev)
   plot(df, add = T)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/VAI1f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VAI1f.png" alt="enter image description here"></a></p>
  
  <p>For each of my 0.25 * 0.25 degree grid square, I want to calculate the mean elevation. How can I do it in R?</p>