rescale_to_int: Rescale Positive Vectors or Matrices to Integers

View source: R/helper_functions.R

rescale_to_intR Documentation

Rescale Positive Vectors or Matrices to Integers

Description

rescale_to_int rescales the non-zero elements of real-valued numeric vectors or matrices to integers in the closed interval [1, max]. Any zero-valued elements are left unchanged.

Usage

rescale_to_int(x, max, colwise = TRUE)

Arguments

x

numeric matrix or vector of non-negative real numbers.

max

the value of largest element in the rescaled integer-valued vector.

colwise

(logical) rescale the matrix by column if TRUE (the default) or by row if FALSE.

Value

rescale_to_int returns a matrix of integers corresponding to x in which smallest non-zero element in each column/row is 1 and the largest element is max. Any elements having value zero are unchanged. If x is a vector then the result is an r x 1 matrix, where r is the number of elements in x. Otherwise the result is a r x c matrix where c is the number of columns in x.

See Also

rescale

Examples

x <- c(0.55, 1.21, 0.94, 0, 0.13)
rescale_to_int(x, max = 5)

sgutreuter/screenr documentation built on Nov. 20, 2022, 2:41 a.m.