Learn R Programming

rcaiman (version 2.0.1)

normalize_minmax: Normalize data using min-max rescaling

Description

Rescale numeric or raster data from an expected range to the range \([0, 1]\).

Usage

normalize_minmax(r, mn = NULL, mx = NULL, clip = FALSE)

Value

Same properties as r, with values rescaled to the range \([0, 1]\) if mn and mx match the range of r or extend beyond it. If clip = TRUE, values will be within \([0, 1]\) even if this implies data loss.

Arguments

r

numeric terra::SpatRaster or numeric vector. Input data.

mn

numeric vector of length one or NULL. Minimum expected value. If NULL (default), uses the minimum of r.

mx

numeric vector of length one or NULL. Maximum expected value. If NULL (default), uses the maximum of r.

clip

logical vector of length one. If TRUE, clip the output to \([0, 1]\) after rescaling. If FALSE, values greater than mx are scaled proportionally to values above 1, and values less than mn to values below 0.

Examples

Run this code
normalize_minmax(read_caim())

Run the code above in your browser using DataLab