I have a SpatialPolygonsDataFrame with 120 Polygons and some associated data. Now I’d like to extract the mean of the values on a raster within each polygon separately. I succeded in plotting individual polygons with:
plot(SpatialPolygons(SPdataframe@polygons)[i])
But it did not work to extract the values in the same manner:
extract(raster, SpatialPolygons(SPdataframe@polygons)[i],fun="mean",na.rm=TRUE,method="simple")
Can anyone explain the difference between the use of the same indexation in this two cases? What is the official way to choose particular polygons of a SpatialPolygonsDataFrame with indices?
Thank you a lot for your help in advance!