Apologies for my question being cumbersome. What I am trying to do is generate a raster where a random 1% of the layer pixels have values, and of these valued pixels, a random 35% have value 1, 55% have value 2, and 10% have value 3. The rest of the pixels should take on the 'no data' marker in R ("NA").
It's easy enough creating a raster with 1% of the pixels with a uniform value using the following code:
pixels <- raster(ext = extent(-120, -119, 49, 50), resolution = c(0.001, 0.001), crs = CRS("+proj=longlat +datum=WGS84"), vals = 1)
testing <- sampleRandom(pixels, size = as.integer(0.01*ncell(pixels)), asRaster = TRUE)
However, I am unsure how to then divide the valued pixels of testing
into three categories and set the values of these categories according to the above.
Is this possible, or else another way of achieving what I am after?
Aucun commentaire:
Enregistrer un commentaire