How to subset SpatialGrid using SpatialPolygon
I am trying to subset the SpatialGrid with 1 polygon present in class SpatialPolygons . How can I do this? I tried it this way: grd.clip <- grd[!is.na(over(grd, polygon))] But I get error Error in matrix(idx, gr@cells.dim[2], gr@cells.dim[1], byrow = TRUE)[rows, : (subscript) logical subscript too long I've tried a way that turn out not to be the desired solution. I'll keep it here for illustrate my original idea but I'll willing to delete it if necessary The solution to the initial question still not clear to me but I'll make it better if necessary library(sp) library(rgdal) library(raster)