layerCor,GRaster-method | R Documentation |
This function returns a correlation or covariance matrix between two or more GRaster
layers. This function returns the sample correlation and covariance (i.e., the denominator is n - 1).
## S4 method for signature 'GRaster'
layerCor(x, fun = "cor")
x |
A |
fun |
Character: Name of the statistic to calculate; either |
A numeric matrix
.
terra::layerCor()
, stats::cor()
, stats::cov()
if (grassStarted()) {
# Setup
library(terra)
# Example data
madChelsa <- fastData("madChelsa")
# Convert a SpatRaster to a GRaster:
chelsa <- fast(madChelsa)
# Correlation
layerCor(chelsa, "cor")
# Covariance
layerCor(chelsa, "cov")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.