When subsetting a matrix or DF, it is possible to reference row columns, such as df1[1:5, 3:10]
, or df3[2:4, ]
.
Is there any way to do this with a raster? That is, can I clip just rows 500:700, for example from a raster object?
I have tried using rasterFromCells()
, but it doesn't give me the result I want (and it seems like there should be a more simple solution given R's other slick subsetting methods).
Example:
r <- raster(ncols = 50, nrow = 50)
r[] <- 1:ncell(r)
# I would like to subset the bottom 50 rows of cells, but keep it as a raster.
# However, this returns a numeric object.
rSub <- r[30:50, 1:50]
Thanks!