Last chance! 50% off unlimited learning
Sale ends in
crop
if you (also) want to remove rows or columns.
There is also an expand method for extent objects to enlarge (or reduce) an Extent. You can also use algebraic notation to do that (see examples)## S3 method for class 'Raster':
expand(x, y, value=NA, filename='', ...)
## S3 method for class 'Extent':
expand(x, y, ...)
x
is a Raster object, y
should be an Extent object, or any object that is or has an Extent object, or an object from which it can be extracted (such as sp objects). Alternatively, you can provide a vector of length 2 with the writeRaster
crop
, merge
r <- raster(xmn=-150, xmx=-120, ymx=60, ymn=30, ncol=36, nrow=18)
r[] <- 1:ncell(r)
e <- extent(-180, 0, 0, 90)
re <- expand(r, e)
# expand with a number of rows and columns (at each side)
re2 <- expand(r, c(2,10))
# Extent object
e <- extent(r)
e
expand(e, 10)
expand(e, 10, -10, 0, 20)
e + 10
e * 2
Run the code above in your browser using DataLab