## ----raster-5, fig=TRUE , echo=TRUE------------------------------------------- library(raster) r <- raster() r[] <- 1:ncell(r) ra <- aggregate(r, 10) r1 <- crop(r, extent(-180,0,0,30)) r2 <- crop(r, extent(-10,180,-20,10)) m <- merge(r1, r2, filename='test.grd', overwrite=TRUE) plot(m) ## ----raster-6----------------------------------------------------------------- r <- raster(ncol=3, nrow=2) values(r) <- 1:ncell(r) getValues(r) s <- calc(r, fun=function(x){ x[x < 4] <- NA; return(x)} ) as.matrix(s) t <- overlay(r, s, fun=function(x, y){ x / (2 * sqrt(y)) + 5 } ) as.matrix(t) u <- mask(r, t) as.matrix(u) v <- u==s as.matrix(v) w <- cover(t, r) as.matrix(w) x <- reclassify(w, c(0,2,1, 2,5,2, 4,10,3)) as.matrix(x) y <- subs(x, data.frame(id=c(2,3), v=c(40,50))) as.matrix(y) ## ----raster-7----------------------------------------------------------------- r <- raster(nrow=45, ncol=90) r[] <- round(runif(ncell(r))*3) a <- area(r) zonal(a, r, 'sum') ## ----raster-10---------------------------------------------------------------- r <- raster(ncol=36, nrow=18) r[] <- runif(ncell(r)) cellStats(r, mean) s = r s[] <- round(runif(ncell(r)) * 5) zonal(r, s, 'mean') freq(s) freq(s, value=3) crosstab(r*3, s)