normalize: Normalize the values of the array by given margin

Description Usage Arguments Value Examples

View source: R/normalize.R

Description

By normalization we understand dividing each value of the cell by a sum computed along the given MARGIN. The summation and division may be replaced with custom functions SUM and DIV, respectively.

Usage

1
normalize(x, MARGIN = seq_len(length(dim(x) - 1)), SUM = sum, DIV = `/`)

Arguments

x

An array to be normalized

MARGIN

A margin, over which to perform the normalization.

SUM

The summationfunction

DIV

The division function

Value

An array of dimensions equal to x with normalized values

Examples

1
2
3
4
5
m <- matrix(1:12, nrow=4)
r <- normalize(m, 1)   # normalize over the rows
rowSums(r)             # returns a vector of 1s
s <- normalize(m, 2)   # normalize over the columns
colSums(s)             # returns a vector of 1s

beerda/hexmatrix documentation built on May 2, 2021, 4:15 a.m.