Does anyone know why rasterize will return the following error when used on polygons:
Error in rv[[ii]] : subscript out of bounds
Using other common R functions like mean also gives the same error, but rasterize options like 'last' work fine. I have not encountered this problem in the past in previous versions of raster (currently using raster_2.3-0). I attached the code that I grabbed from the example in ?rasterize :
library(raster) p1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20)) hole <- rbind(c(-150,-20), c(-100,-10), c(-110,20), c(-150,-20)) p1 <- Polygons(list(Polygon(p1), Polygon(hole, hole=TRUE)), 1) p2 <- Polygons(list(Polygon(rbind(c(-10,0), c(140,60), c(160,0), c(140,-55), c(-10,0)))), 2) p3 <- Polygons(list(Polygon(rbind(c(-125,0), c(0,60), c(40,5), c(15,-45), c(-125,0)))), 3) pols <- SpatialPolygons( list( p1 , p2, p3) ) r <- raster(ncol=90, nrow=45) r <- rasterize(pols, r, fun='sum')