Learn R Programming

terra (version 0.5-2)

spatSample: Take a regular sample

Description

Take a regular sample of a SpatRaster. Either get cell values, or a new SpatRaster with the same extent, but fewer cells.

Usage

# S4 method for SpatRaster
spatSample(x, size, method="regular", replace=FALSE, as.raster=FALSE, ...)

Arguments

x

SpatRaster

size

numeric. The sample size

method

character. Should be "regular" or "random"

replace

logical. If TRUE, sampling is with replacement (if method="random"

as.raster

logical. If TRUE and method="regular", a SpatRaster is returned

...

additional arguments. None implemented

Value

numeric or SpatRaster

Examples

Run this code
# NOT RUN {
f <- system.file("exdata/test.tif", package="terra")
r <- rast(f)
s <- spatSample(r, 10, as.raster=TRUE)
spatSample(r, 10)
spatSample(r, 10, "random")
# }

Run the code above in your browser using DataLab