Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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.

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.

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.

See Also

Sequence Properties
(Other than unique-related properties).

Examples

x <- c (2, 1, 0, 1, 2, 1, 0, 1, 2)
which.mins (x)
mins (x)

vectools

Advanced Vector Toolkit

v0.2.0
GPL (>= 2)
Authors
Abby Spurdle
Initial release
2020-10-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.