normalize: Normalize a vector of values

Description Usage Arguments Examples

View source: R/stats.R

Description

Normalize to sum to one, sum to zero, or as a proportion of max value, etc...

Usage

1
normalize(x, type = "minmax", na.rm = TRUE)

Arguments

x

scalar or vector of numeric values

type

character of the type of normalization to perform. Defaults to "minmax"

na.rm

remove NAs before normalizing. Otherwise will return all NAs if any exist

Examples

1
2
3
4
5
6
7
8
x <- c(-14, -10, -2, 0, NA, 1, 5, 6)
normalize(x, "minmax")  # all values compressed within the range of 0 to 1 (default)
normalize(x, "s0")      # all values will sum to zero with a range of -1 to 1.
normalize(x, "s1")      # all values will sum to one with a range of -1 to 1.
normalize(x, "l1")      # all values as a proportion of the largest absolute value
normalize(x, "l2")      # all values as a proportion of the largest squared value
normalize(x, "simplex") # all values will sum to one and are within the range of 0 to 1.
normalize(x, "softmax") # all values will sum to one and are greater than zero and less than one. One hot vector

iamamutt/mejr documentation built on May 18, 2019, 1:27 a.m.