Learn R Programming

functools (version 0.2.0)

Best: Find the best value in a vector.

Description

Best() takes a vector .x and a binary predicate function .f and returns the result of .f reduced over .x.

Usage

Best(.x, .f)

Arguments

.x
A vector.
.f
A binary predicate function.

Value

The best value in that vector, as determined by the binary predicate function.

Examples

Run this code
# Simulate the behavior of max with numerics
Best(1:10, function(x, y) return(x > y))
# Simulate the behavior of min with numerics
Best(1:10, function(x, y) return(x < y))
# This comparison function prefers values that begin with l
Best(letters, function(x, y) return(x[1] == "l"))

Run the code above in your browser using DataLab