I have a raster as a RasterLayer (raster) and a polygon layer (bound) with 38 individual polygons as a SpatialPolygonsDataFrame. I used the polygon to mask from a larger raster. Each polygon contains either 4 or 5 individual pixels.
I want to extract the cell values by the name of each individual polygon. I know I can do this:
v <- extract(raster, bound) v.counts <- lapply(v,table)
But this ends up looking like this:
> v.counts [] 0.0463505908846855 0.0503523759543896 0.0531094446778297 0.0665162950754166 1 1 1 1 [] 0.0755022615194321 0.0766473188996315 0.0860441327095032 0.612392961978912 0.689212620258331 1 1 1 1 1
Is there a different way to do this or a way to get the name field associated with the bound polygon to appear in the parentheses in the above output? For example [[Reservoir A]] instead of ?
Could this have anything to do with how the individual polygons are named in the shapefile? For example if you view the "polygons" portion in view, each polygon is named , [] etc. :
Is there a way to just simply change the name of the polygon to get my intended output?