title: Aggregate raster by a non-integer factor with arbitrary function
body: <p>I would like to aggregate a population raster by a factor of 1.5, summing the values of the cells.</p>
  
  <p>While <code>aggregate()</code> allows me to sum values when aggregating, its <code>factor</code> parameter accepts only integer values. <code>projectRaster()</code> and <code>resample()</code> allow me to adjust the resolution precisely, but (as far as I know) I am restricted to the prepackaged bilinear-interpolation and nearest-neighbor computation methods.</p>
  
  <p>Is there a way to aggregate a raster by a non-integer factor AND specify the function to use when aggregating?</p>
  
  <pre><code>library(raster)
  set.seed(10)
  
  proj &lt;- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
  r &lt;- raster(resolution = 1, nrow = 100, crs = proj)
  r[] &lt;- round(rnorm(ncell(r), 100, 10))
  
  # Doesn't accept non-integer factors
  aggregate(r, fact = 1.5, fun = sum)
  
  template &lt;- raster(extent(r), crs = crs(r), resolution = 1.5)
  
  # Correct resolution, but incorrect / impossible values for population
  projectRaster(r, to = template, method = "ngb")
  projectRaster(r, to = template, method = "bilinear")
  </code></pre>
  
  <h2>Possible workaround</h2>
  
  <p>So far, the only method I've been able to come up with is to coerce the template to a <code>SpatialPoints</code> object; extract values from the original, higher-resolution raster; and <code>rasterize()</code> the result:</p>
  
  <pre><code>pts &lt;- as(template, "SpatialPoints")
  vals &lt;- extract(r, pts)
  pts2 &lt;- SpatialPointsDataFrame(pts, data.frame(vals))
  
  rasterize(pts2, template, field = "vals", fun = sum)
  </code></pre>
  
  <p>However, if the points are created at the centroids of the raster cells, I'm not sure how they are handled when extracting with a resolution of 1.5x the original raster. My preferred method would be to create a <code>SpatialPolygonsDataFrame</code> and rasterize with <code>fun = mean</code>, but (in my experience) extracting raster values using polygons is very inefficient.</p>