Learn R Programming

exams.forge (version 1.0.11)

all_different: 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)

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.

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.

Examples

Run this code
# 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)

Run the code above in your browser using DataLab