Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layerCor() with fun='pearson' misses layer names #1206

Closed
AMBarbosa opened this issue Jun 27, 2023 · 1 comment
Closed

layerCor() with fun='pearson' misses layer names #1206

AMBarbosa opened this issue Jun 27, 2023 · 1 comment

Comments

@AMBarbosa
Copy link
Contributor

AMBarbosa commented Jun 27, 2023

Unlike raster::layerStats() with stat='pearson', terra::layerCor() with fun='pearson' does not include the layer names in the result, although it does if fun='weighted.cov':

library(terra)
b <- rast(system.file("ex/logo.tif", package="terra"))   
w <- init(b, fun="col")


layerCor(b, "pearson", w=w)

# $pearson
#           [,1]      [,2]      [,3]
# [1,] 1.0000000 0.9980961 0.9501633
# [2,] 0.9980961 1.0000000 0.9658011
# [3,] 0.9501633 0.9658011 1.0000000
# 
# $mean
#          [,1]     [,2]     [,3]
# [1,]      NaN 182.2855 182.2855
# [2,] 185.3509      NaN 185.3509
# [3,] 192.8046 192.8046      NaN


layerCor(b, "weighted.cov", w=w)

# $weighted_covariance
#            red    green     blue
# red   5670.750 5536.351 5009.851
# green 5536.351 5427.161 4987.092
# blue  5009.851 4987.092 4937.007
# 
# $weighted_mean
#      red    green     blue 
# 177.5983 181.3521 191.5236 

It'd be great if layer names were included for 'pearson' too. Cheers!

@rhijmans
Copy link
Member

Thank you. I now get

layerCor(b, "pearson", w=w)
#$pearson
#            red     green      blue
#red   1.0000000 0.9980961 0.9501633
#green 0.9980961 1.0000000 0.9658011
#blue  0.9501633 0.9658011 1.0000000
#
#$mean
#           red    green     blue
#red        NaN 182.2855 182.2855
#green 185.3509      NaN 185.3509
#blue  192.8046 192.8046      NaN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants