I have numerous large stacked raster file with multiple layers and I would like to select 250 random points and extract the data values from all layers for these points.
I had been using the raster package sampleRandom(raster,n, na.rm=TRUE, xy=TRUE) to select random points before extracting the data from my raster object but this works without replacement. I, however, would like to sample random points from the raster files with replacement as can be done with the r base package sample(x, size, replace = TRUE, prob = NULL).
I had considered just running a loop using sampleRandom so that each point has a chance of being sampled for each of the 250 runs;
samp_all <- matrix(, nrow = 250, ncol = 10)
for (i in 1:250)
{samp <- sampleRandom(layer1, 1, xy = TRUE, na.rm = TRUE)[, -3]
samp_all[i,] <- samp}
samp2 <- extract(stack_all, samp_all)
But this seems to run pretty slowly and I have quite a lot of files I would like to run this on.
Is there a simpler way to randomly sample points from raster layers with replacement that would allow me to extract data from my raster?