I have an sfc Multipolygon data.frame with roughly 7000 polygons. Now I want to extract the mean cell values for each polygon that overlaps a raster file with a resolution of 2x2m (many many cells) and only 1 band. I found this question and adapted the bottom answer to my data. Here is the approach from the other question:
r1 <- raster
p1 <- polygon feature
p1$mean_val <- raster::extract(x = r1, y = p1, FUN=mean)
When I try this, I get an error message saying
invekos_shp$mean_SOC_gkg <- raster::extract(x=SOC_raster_2x2,
y=invekos_shp,FUN=mean, na.rm=TRUE)
Error in `[[<-.data.frame`(`*tmp*`, i, value = list(ID = c(1, 1, 1, 1,
: Substitution has 161486089 lines, Data has 7077
Is this because my data frame is a multipolygon data frame or did I not adapt the function correctly? Can I read the shape file in a different format to be able to use this function or would I loose information by that?