Learn R Programming

exams.forge (version 1.0.10)

nearest_arg: Nearest Candidate Value

Description

It determines the nearest candidate value for each value in arg. As a replacement for [base::match.arg], it is more error-tolerant, but detecting a wrong choice can be proven challenging.

Usage

nearest_arg(arg, choices, method = "cosine", ...)

Value

For each value in arg the (first) nearest element of choices.

Arguments

arg

character: vector or NULL

choices

character: vector of candidate values

method

character: method for distance calculation (default: cosine)

...

further parameters for stringdist::stringdistmatrix

Examples

Run this code
# match.arg("tow.sided", c("two.sided", "less", "greater")) # will fail
nearest_arg("tow.sided", c("two.sided", "less", "greater")) 
nearest_arg(c("two.sided", "less", "greater"), c("two.sided", "less", "greater"))
nearest_arg(c("two", "two", "ded", "ss", "ea"), c("two.sided", "less", "greater"))

Run the code above in your browser using DataLab