runifRast: Create a raster with random values drawn from a uniform...

runifRast,GRaster-methodR Documentation

Create a raster with random values drawn from a uniform distribution

Description

runifRast() creates a raster with values drawn from a uniform (flat) distribution.

Usage

## S4 method for signature 'GRaster'
runifRast(x, n = 1, low = 0, high = 1, seed = NULL)

Arguments

x

A GRaster. The output will have the same extent and dimensions as this raster.

n

A numeric integer: Number of rasters to generate.

low, high

Numeric: Minimum and maximum values from which to select.

seed

Numeric integer vector or NULL: Random seed. If NULL, then a different seed will be generated by GRASS. Defining this is useful if you want to recreate rasters. If provided, there should be one seed value per raster.

Value

A GRaster.

See Also

rnormRast(), rSpatialDepRast(), fractalRast(), GRASS manual page for module r.random.surface (see grassHelp("r.random.surface"))

Examples

if (grassStarted()) {

# Setup
library(sf)
library(terra)

# Elevation raster
madElev <- fastData("madElev")

# Convert a SpatRaster to a GRaster:
elev <- fast(madElev)

### Create a raster with values drawn from a uniform distribution:
unif <- runifRast(elev)
plot(unif)

### Create a raster with values drawn from a normal distribution:
norms <- rnormRast(elev, n = 2, mu = c(5, 10), sigma = c(2, 1))
plot(norms)
hist(norms, bins = 100)

# Create a raster with random, seemingly normally-distributed values:
rand <- rSpatialDepRast(elev, dist = 1000)
plot(rand)

# Values appear normal on first inspection:
hist(rand)

# ... but actually are patterned:
hist(rand, bins = 100)

# Create a fractal raster:
fractal <- fractalRast(elev, n = 2, dimension = c(2.1, 2.8))
plot(fractal)
hist(fractal)

}

adamlilith/fasterRaster documentation built on Dec. 21, 2024, 2:04 a.m.