all_different: Difference Testing Functions

View source: R/all_different.R

all_differentR Documentation

Difference Testing Functions

Description

These functions determine whether numeric values are sufficiently different from each other based on a specified tolerance.

  • all_different: Checks if all differences between entries in a numeric object exceed a given tolerance.

  • values_different: Adds candidate values to a set of initial values only if they are sufficiently different from all existing values.

Usage

all_different(obj, tol)

values_different(values, candidates, tol = 0.1)

Arguments

obj

Numeric vector, matrix, or data frame to test for differences. Non-numeric inputs will be coerced to numeric if possible.

tol

Numeric scalar specifying the minimum allowable difference between values.

values

Numeric vector of initial values.

candidates

Numeric vector of candidate values to add if sufficiently different.

Value

  • all_different: Logical (TRUE if all differences exceed tol, FALSE otherwise).

  • values_different: Numeric vector with original values plus any candidates that meet the difference criterion.

Examples

# Check if all values are sufficiently different
x <- runif(10)   # 10 random values between 0 and 1
all_different(x, tol = 0.01)
all_different(x, tol = 0.5)

# Add sufficiently different candidate values
starting_values <- c(0.1, 0.5, 0.9)
candidates <- c(0.15, 0.4, 0.8, 1.2)
values_different(starting_values, candidates, tol = 0.2)

exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.