diff --git a/R/princomp.R b/R/princomp.R index 34bc48518..0b50f19e9 100644 --- a/R/princomp.R +++ b/R/princomp.R @@ -3,10 +3,9 @@ setMethod("princomp", signature(x="SpatRaster"), function(x, cor=FALSE, nobs=FALSE) { stopifnot(nlyr(x) > 1) - xcov <- layerCor(x, fun = "cov", na.rm = TRUE) - model <- princomp(covmat = xcov$covariance) + xcov <- layerCor(x, fun="cov", na.rm=TRUE) + model <- princomp(covmat = xcov$covariance) model$center <- diag(xcov$mean) - model$n.obs <- ncell(x) - global(anyNA(x), sum)$sum if (cor) { ## Calculate scale as population sd like in in princomp model$n.obs <- ncell(x) - global(anyNA(x), sum)$sum