Skip to content

Calculation of median/quantiles #113

@akdixon

Description

@akdixon

I'm trying to calculate the median value of the pixels within a polygon using exact_extract, but it's giving me weird values. Here's some example code.

rast <- raster::raster(matrix(c(0,0,0,0,10,0,0,0,0), ncol=3),xmn=0, ymn=0, xmx=3, ymx=3)
poly <- sf::st_as_sfc('POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))')
exact_extract(rast, poly, "median")
exact_extract(rast, poly, "quantile", quantiles = 0.5)
exact_extract(rast, poly, "mean")

The mean seems correct with an output of 2.5, but for "median" it's producing 5. Shouldn't it be 0 if the values used are 0, 0, 0, 10? Am I misunderstanding something about how the median/quantiles are calculated? I'm not great at coding and definitely could have missed something in the documentation, so sorry if this is answered somewhere else. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions