If I have a raster contain cells with integer values (say 1 to 10), and I'd like to know the percentage cover for each value type, from a subset of the raster as determined by an sf polygon, how should I go about doing this? I'd like to return a vector containing percentages (one for each value type), for a given bounding polygon. I thought it would be something along the lines of:
If I have a raster contain cells with integer values (say 1 to 10), and I'd like to know the percentage cover for each value type, from a subset of the raster as determined by an
sf
polygon, how should I go about doing this? I'd like to return a vector containing percentages (one for each value type), for a given bounding polygon. I thought it would be something along the lines of:exact_extract(raster, poly_sf, function(value) count(value)/no_of_cells_in_poly_sf)
But I'm not sure how to extend this to return a vector for the % cover for each value type. Thank you