scaleRng: Scale Data

View source: R/scaleRng.R

scaleRngR Documentation

Scale Data

Description

Transforms numeric data to a specified range.

Usage

scaleRng(x, Min = 0, Max = 1, x.range = range(x, na.rm = TRUE))

IscaleRng(x, Min, Max, x.range)

Arguments

x

any numeric vector. Missing values are permitted and result in missing values in the corresponding output.

Min

the minimum of the output range.

Max

the maximum of the output range.

x.range

the input range to map to the output range. The default range is computed from the range of x after removing missing values.

Details

The function scaleRng maps the minimum of x.range to Min and the maximum of x.range to Max and uses linear interpolation for other values in x.

Value

A numeric vector scaled to the specified range.

Note

Some applications recommend or require data scaled to a consistent range. The function scaleRng will do that and can be used to back-transform the data.

Examples


## simple case with back-transform
x.tmp <- print(scaleRng(c(1.2, 2.3, 3.4, 5.6)))
IscaleRng(x.tmp)
## now set the expected ranges
x.tmp <- print(scaleRng(c(1.2, 2.3, 3.4, 5.6), x.range=c(1, 6)))
IscaleRng(x.tmp)


USGS-R/smwrBase documentation built on Oct. 18, 2022, 9:55 a.m.