## ----raster-15---------------------------------------------------------------- library(terra) r <- rast(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, cbind(0,0)) colFromX(r, 0) rowFromY(r, 0) ## ----raster-20---------------------------------------------------------------- r <- rast(system.file("ex/meuse.tif", package="terra")) v <- values(r) v[708:712] ## ----raster-21---------------------------------------------------------------- cells <- cellFromRowCol(r, 50, 35:39) cells r[cells] xy <- xyFromCell(r, cells) xy extract(r, xy) ## ----raster-32---------------------------------------------------------------- #r[cells] #r[1:4] #sources(r) #r[2:3] <- 10 #r[1:4] #sources(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]