## ----raster-15---------------------------------------------------------------- library(raster) r <- raster(ncol=36, nrow=18) ncol(r) nrow(r) ncell(r) rowFromCell(r, 100) colFromCell(r, 100) cellFromRowCol(r,5,5) xyFromCell(r, 100) cellFromXY(r, c(0,0)) colFromX(r, 0) rowFromY(r, 0) ## ----raster-20---------------------------------------------------------------- r <- raster(system.file("external/test.grd", package="raster")) v <- getValues(r, 50) v[35:39] getValuesBlock(r, 50, 1, 35, 5) ## ----raster-21---------------------------------------------------------------- cells <- cellFromRowCol(r, 50, 35:39) cells extract(r, cells) xy <- xyFromCell(r, cells) xy extract(r, xy) ## ----raster-32---------------------------------------------------------------- r[cells] r[1:4] filename(r) r[2:3] <- 10 r[1:4] filename(r) ## ----raster-33---------------------------------------------------------------- r[1] r[2,2] r[1,] r[,2] r[1:3,1:3] # keep the matrix structure r[1:3,1:3, drop=FALSE]