Scale values
scale.Rd
Center and/or scale raster data. For details see scale
Arguments
- x
SpatRaster
- center
logical or numeric. If
TRUE
, centering is done by subtracting the layer means (omittingNA
s), and ifFALSE
, no centering is done. Ifcenter
is a numeric vector (recycled tonlyr(x)
), then each layer ofx
has the corresponding value from center subtracted from it.- scale
logical or numeric. If
TRUE
, scaling is done by dividing the (centered) layers ofx
by their standard deviations ifcenter
isTRUE
, and the root mean square otherwise. If scale isFALSE
, no scaling is done. Ifscale
is a numeric vector (recycled tonlyr(x)
), each layer ofx
is divided by the corresponding value. Scaling is done after centering.
Examples
r <- rast(system.file("ex/logo.tif", package="terra"))
s <- scale(r)
## the equivalent, computed in steps
m <- global(r, "mean")
rr <- r - m[,1]
rms <- global(rr, "rms")
ss <- rr / rms[,1]