Random sampling of raster using R?
You can adapt examples from the Raster
package vignette, section 5.2. Here's one way:
r <- raster(ncol=30,nrow=20)
r[] <- 1:(30*20) # Raster for testing
#plot(r) # (If you want to see it)
r[runif(30*20) >= 0.30] <- NA # Randomly *unselect* 70% of the data
plot(r)
You can use the sampleRandom
function:
library(raster)
r <- raster(ncol=30,nrow=20)
r[] <- 1:ncell(r)
x <- sampleRandom(r, ncell(r)*.3, asRaster=TRUE)