reverse_scale: Reverse a scale

View source: R/simple_math.R

reverse_scaleR Documentation

Reverse a scale

Description

Reverses a scale so that the largest number becomes the smallest, next largest becomes next smallest, etc. Can be given scale limits but will determine them empirically if not given.

Usage

reverse_scale(x, .min = min(x, na.rm = T), .max = max(x, na.rm = T))

Arguments

x

(numeric vector) A vector of values.

.min

(numeric scalar) The scale maximum. Defaults to the observed minimum.

.max

(numeric scalar) The scale minimum. Defaults to the observed maximum.

Examples

x = c(2, 1, 3, 0, -1) #some scale ranging from -1 to 3
reverse_scale(x) #reverse scores: 3 becomes -3
x == reverse_scale(reverse_scale(x)) #reverse twice and get back
reverse_scale(x, .min = -3, .max = 10) #supply other min/max

Deleetdk/kirkegaard documentation built on Feb. 28, 2025, 5:04 p.m.