title: Changing the raster spatial extent in R
body: <p>I have two rasters and I want to make the spatial extent of one to another. Then save it as a new raster. I used following code. However, I cannot save the 2013 images with new spatial extent as a new raster. Any guidance is greatly appreciated.  </p>
  
  <pre><code>raster_2013 &lt;- raster("avgt2013.tif")
  extent(raster_2013)
  class       : Extent 
  xmin        : 112.91 
  xmax        : 153.64 
  ymin        : -43.75 
  ymax        : -9 
  &gt; res(raster_2013)
  [1] 0.01 0.01
  &gt; 
  &gt; raster_2015 &lt;- raster("avgt2015.tif")
  &gt; extent(raster_2015)
  class       : Extent 
  xmin        : 112 
  xmax        : 154 
  ymin        : -44 
  ymax        : -9 
  &gt; res(raster_2015)
  [1] 0.01 0.01
  &gt; 
  &gt; e &lt;- extent(112, 154, -44, -9)
  &gt; 
  &gt; ex = extent(raster_2015)
  &gt; r2 = crop(raster_2013, ex)
  &gt; 
  &gt; 
  &gt; new_2013 &lt;- alignExtent(e, raster_2013, snap='near')
  &gt; str(new_2013)
  Formal class 'Extent' [package "raster"] with 4 slots
    ..@ xmin: num 112
    ..@ xmax: num 154
    ..@ ymin: num -44
    ..@ ymax: num -9
  &gt; 
  &gt; rc &lt;- crop(raster_2013, e, snap='near')
  &gt; extent(rc)
  class       : Extent 
  xmin        : 112.91 
  xmax        : 153.64 
  ymin        : -43.75 
  ymax        : -9 
  </code></pre>