arg.min: Find arguments that minimize a function

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/r-utility-argminmax.R

Description

This function applies a numeric-valued function to a vector or list of arguments and returns a specified number of arguments that yield the least function values. It is used in examples presented in the book Cichosz, P. (2015): Data Mining Algorithms: Explained Using R. See Appendix B or http://www.wiley.com/go/data_mining_algorithms for more details.

Usage

1
arg.min(args, fun, k = 1)

Arguments

args

a vector or list of function arguments

fun

a function that can be called with one argument and returns a numeric value

k

an integer specifying the number of arguments corresponding to the least function values to return

Details

The fun function is applied to each argument in args and then the k arguments that produced the least function values are returned. Ties are broken according to the original ordering of arguments (using stable sorting to determine the least k values).

Value

If args is a list, its sublist of length k containing the k arguments that yield the least fun values. If args is a vector, its subvector of length k containing the k arguments that yield the least fun values.

Author(s)

Pawel Cichosz <p.cichosz@elka.pw.edu.pl>

See Also

arg.max

Examples

1
2
3
4
5
6
arg.min(1:10, sin)
arg.min(1:10, sin, 3)

data(weatherr, package="dmr.data")
arg.min(1:nrow(weatherr), function(i) weatherr$playability[i], 3)
arg.min(weatherr$temperature, function(temp) abs(temp-20), 3)

42n4/dmr.util documentation built on May 20, 2019, 2:02 p.m.