Aliases: subset subset,SpatRaster-method [[,SpatRaster,numeric,missing-method [[,SpatRaster,logical,missing-method [[,SpatRaster,character,missing-method [,SpatRaster,character,missing-method [,SpatRasterDataset,numeric,missing-method [,SpatRasterDataset,numeric,numeric-method [,SpatRasterDataset,logical,missing-method [,SpatRasterDataset,character,missing-method [[,SpatRasterDataset,ANY,ANY-method [,SpatRasterCollection,numeric,missing-method $,SpatRaster-method $,SpatRasterDataset-method
Keywords: spatial
### ** Examples s <- rast(system.file("ex/logo.tif", package="terra")) subset(s, 2:3)
class : SpatRaster dimensions : 77, 101, 2 (nrow, ncol, nlyr) resolution : 1, 1 (x, y) extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax) coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs source : logo.tif names : green, blue min values : 0, 0 max values : 255, 255
subset(s, c(3,2,3,1))
class : SpatRaster dimensions : 77, 101, 4 (nrow, ncol, nlyr) resolution : 1, 1 (x, y) extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax) coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs source : logo.tif names : blue, green, blue, red min values : 0, 0, 0, 0 max values : 255, 255, 255, 255
#equivalent to s[[ c(3,2,3,1) ]]
class : SpatRaster dimensions : 77, 101, 4 (nrow, ncol, nlyr) resolution : 1, 1 (x, y) extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax) coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs source : logo.tif names : blue, green, blue, red min values : 0, 0, 0, 0 max values : 255, 255, 255, 255
s[[c("red", "green")]]
class : SpatRaster dimensions : 77, 101, 2 (nrow, ncol, nlyr) resolution : 1, 1 (x, y) extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax) coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs source : logo.tif names : red, green min values : 0, 0 max values : 255, 255
s$red
class : SpatRaster dimensions : 77, 101, 1 (nrow, ncol, nlyr) resolution : 1, 1 (x, y) extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax) coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs source : logo.tif name : red min value : 0 max value : 255
# expresion based (partial) matching of names with single brackets s["re"]
class : SpatRaster dimensions : 77, 101, 2 (nrow, ncol, nlyr) resolution : 1, 1 (x, y) extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax) coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs source : logo.tif names : red, green min values : 0, 0 max values : 255, 255
s["^re"]
class : SpatRaster dimensions : 77, 101, 1 (nrow, ncol, nlyr) resolution : 1, 1 (x, y) extent : 0, 101, 0, 77 (xmin, xmax, ymin, ymax) coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs source : logo.tif name : red min value : 0 max value : 255
# not with double brackets # s[["re"]]