# NOT RUN {
library(raster)
r1 <- raster(nrows=100, ncol=100)
r1[] <- round(runif(ncell(r1), 1,4),0)
r2 <- raster(nrows=100, ncol=100)
r2[] <- round(runif(ncell(r2), 2,6),0)
r3 <- raster(nrows=100, ncol=100)
r3[] <- round(runif(ncell(r3), 2,6),0)
r <- stack(r1,r2,r3)
names(r) <- c("LC1","LC2","LC3")
# Combine rasters in stack
( cr <- combine(r) )
levels(cr)
# Combine rasters in stack, using specific rasters
( cr <- combine(r, rnames=c("LC1","LC3")) )
# Combine rasters in stack, output SpatialPixelsDataFrame
cr.sp <- combine(r, sp = TRUE)
head(cr.sp$summary)
class(cr.sp$combine)
# Input SpatialPixelsDataFrame
r.sp <- as(r, "SpatialPixelsDataFrame")
cr.sp <- combine(r.sp, sp = TRUE)
# }
Run the code above in your browser using DataLab