Learn R Programming

spatialEco (version 1.3-7)

random.raster: Random raster

Description

Create a random raster or raster stack using specified distribution

Usage

random.raster(
  r = NULL,
  n.row = 50,
  n.col = 50,
  n.layers = 1,
  x = seq(1, 10),
  min = 0,
  max = 1,
  mean = 0,
  sd = 1,
  p = 0.5,
  s = 1.5,
  distribution = c("random", "normal", "seq", "binomial", "gaussian")
)

Value

RasterLayer or RasterStack object with random rasters

Arguments

r

Optional existing raster defining nrow/ncol

n.row

Number of rows

n.col

Number of columns

n.layers

Number of layers in resulting raster stack

x

A vector of values to sample if distribution is "sample"

min

Minimum value of raster

max

Maximum value of raster

mean

Mean of centered distribution

sd

Standard deviation of centered distribution

p

p-value for binomial distribution

s

sigma value for Gaussian distribution

distribution

Available distributions, c("random", "normal", "seq", "binomial", "gaussian", "sample")

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org>

Details

Options for distributions are for random, normal, seq, binomial, gaussian and sample raster(s)

Examples

Run this code
library(raster)

# Using existing raster to create random binomial  
r <- raster(system.file("external/rlogo.grd", package="raster")) 
r <- random.raster(r, distribution="binomial")

# default; random, nrows=50, ncols=50, nlayers=1
rr <- random.raster(n.layer=5)

# specified; binomial, nrows=20, ncols=20, nlayers=5
rr <- random.raster(n.layer=5, n.col=20, n.row=20,  
                    distribution="binomial")

# specified; gaussian, nrows=50, ncols=50, nlayers=1
rr <- random.raster(n.col=50, n.row=50, s=8,  
                    distribution="gaussian")

# 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