Learn R Programming

nnfor (version 0.9.2)

linscale: Apply minmax linear scaling to a vector.

Description

Apply minmax linear scaling to a vector.

Usage

linscale(x, minmax = NULL, rev = c(FALSE, TRUE))

Arguments

x

Input vector.

minmax

minmax must be a list with elements "mn", "mx", "mn.orig" and "mx.orig", where "mn" and "mx" refer to the target min and max, and the remaining two refer to the current vector min and max. By default mn=-1 and mx=1. mn.orig and mx.orig can be missing, unless the scaling is reversed.

rev

Reverse scaling back to original: TRUE or FALSE.

Value

Outputs a list with elements:

  • x - Scaled vector.

  • minmax - List with resulting mn, mx, mn.orig and mx.orig. Can be used as input to reverse scaling.

Examples

Run this code
# NOT RUN {
  y <- rnorm(20)*100
  sc <- linscale(y)
  x <- sc$x
  print(c(min(y),max(y)))
  print(c(min(x),max(x)))
  sc.rev <- linscale(x,minmax=sc$minmax,rev=TRUE)
  print(c(min(sc.rev$x),max(sc.rev$x)))

# }

Run the code above in your browser using DataLab