I have a raster dataset that is classified into vegetation classes. I would like to randomly sample from the dataset based on the vegetation classes, but not sure how to do it.
Here is some example code taken from the deratify() function in the package raster.
library(raster) r <- raster(nrow=10, ncol=10) r = 1 r[51:100] = 2 r[3:6, 1:5] = 3 r <- ratify(r) rat <- levels(r)[] rat$landcover <- c('Pine', 'Oak', 'Meadow') rat$code <- c(12,25,30) levels(r) <- rat x <- deratify(r, 'landcover')
What I would like to do is to sample N number of cells (or points) from each class in x (Pine, Oak, Meadow).
Any hints on how to do this without subsetting the raster?