library(terra)
# Using existing raster to create random binominal
r <- rast(system.file("ex/elev.tif", package="terra"))
( rr <- random.raster(r, n.layers = 3, distribution="binominal") )
plot(c(r,rr))
# default; random, nrows=50, ncols=50, n.layers=5
( rr <- random.raster() )
# specified; binominal, nrows=20, ncols=20, nlayers=5
( rr <- random.raster(n.layer=5, n.col=20, n.row=20,
distribution="binominal") )
# specified; gaussian, nrows=50, ncols=50, nlayers=1
( rr <- random.raster(n.col=50, n.row=50, s=8,
distribution="gaussian") )
plot(rr)
# specified; sample, nrows=50, ncols=50, nlayers=1
( rr <- random.raster(n.layer=1, x=c(2,6,10,15),
distribution="sample" ) )
freq(rr)
Run the code above in your browser using DataLab