Learn R Programming

vectools (version 0.2.0)

42_optimization-related_functions: Optimization-Related Functions

Description

Sequence based functions, involving indices (or intervals) of minima or maxima.

Usage

which.mins (x, …, ret.type="I", endpoints=FALSE)
which.maxs (x, …, ret.type="I", endpoints=FALSE)
which.opts (x, …, ret.type="I", endpoints=FALSE)

mins (x, …, intervals.ok=FALSE, endpoints=FALSE) maxs (x, …, intervals.ok=FALSE, endpoints=FALSE) opts (x, …, intervals.ok=FALSE, endpoints=FALSE)

Arguments

x

An integer/numeric vector.

intervals.ok

Logical, if true, optimal regions are allowed, if false (and there are optimal regions), an error is generated.

ret.type

String, either: "I" (integer vector of indices) "intervals" (two-column integer matrix, representing intervals) "NMP" (integer vector, same as "NMP-") "NMP-" (integer vector of indices, near mid points, rounds down given even length subintervals) "NMP+" (integer vector of indices, near mid points, rounds up given even length subintervals) "MP" (numeric vector of exact midpoints)

endpoints

Logical vector, of length one or two, to include the first/last values as possible optima.

Ignored.

Value

All "which" functions return an integer vector, which the exception of ret.type="intervals" which returns a two-column integer matrix and ret.type="MP" which returns a numeric vector.

The mins and maxs functions return values from the original vector. They may contain duplicated values.

Details

These functions are designed to find indices or subintervals matching a pattern.

When ret.type="I", the solutions need to be single indices. Otherwise, an error is generated.

When ret.type="intervals" the functions return the starting and ending indices of intervals.

For other return types, a single index is returned for each interval.

See Also

Unique-Related Functions

Sequence Properties (Other than unique-related properties).

Other Sequence Functions

Examples

Run this code
# NOT RUN {
x <- c (2, 1, 0, 1, 2, 1, 0, 1, 2)
which.mins (x)
mins (x)
# }

Run the code above in your browser using DataLab