Learn R Programming

Smisc (version 0.3.9.1)

linearMap: Linear mapping of a numeric vector or scalar

Description

Linear mapping of a numeric vector or scalar from one closed interval to another

Usage

linearMap(x, D = range(x), R = c(0, 1))

Arguments

x

a numeric vector

D

a vector with 2 elements, the first being the lower endpoint of the domain, the upper being the upper endpoint of the domain. Note R[1] must be less than R[2].

R

a vector with 2 elements indicating the range of the linear mapping. R[1] is mapped to D[1], and R[2] is mapped to D[2].

Value

The linear mapping of x from D to R

Details

The mapping is \(f : D --> R\), where \(f(D[1]) = R[1]\) and \(f(D[2]) = R[2]\).

Examples

Run this code
# NOT RUN {
x <- seq(0, 1, length = 5)

# An increasing linear map
linearMap(x, R = c(4, 7))

# A decreasing map
linearMap(x, R = c(7, 4))

# A shift
linearMap(x, R = c(-1, 0))

# The identity map:
y <- linearMap(x, D = c(0, 1), R = c(0, 1))
identical(y, x)
# }

Run the code above in your browser using DataLab