
Scale values
scale.RdCenter 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 (omittingNAs), and ifFALSE, no centering is done. Ifcenteris a numeric vector (recycled tonlyr(x)), then each layer ofxhas the corresponding value from center subtracted from it.- scale
logical or numeric. If
TRUE, scaling is done by dividing the (centered) layers ofxby their standard deviations ifcenterisTRUE, and the root mean square otherwise. If scale isFALSE, no scaling is done. Ifscaleis a numeric vector (recycled tonlyr(x)), each layer ofxis divided by the corresponding value. Scaling is done after centering.
Value
SpatRaster
The result has attributes "scaled:center" and/or "scaled:scale", as in scale, when centering and/or scaling is requested.
Examples
r <- rast(system.file("ex/logo.tif", package="terra"))
s <- scale(r)
attr(s, "scaled:center")
#> [1] 182.2855 185.3509 192.8046
attr(s, "scaled:scale")
#> [1] 74.59471 73.11226 70.44815
## the equivalent, computed in steps
m <- global(r, "mean")
rr <- r - m[,1]
rms <- global(rr, "rms")
ss <- rr / rms[,1]