closest.pos: Positions of elements which are closest to some reference...

Description Usage Arguments Value Examples

View source: R/aux-functions.R

Description

For two vectors X and Y a vector of indices I is returned, such that length(Y) and length(I) coincide and X[I[j]] is an element of X which has minimal distance to Y[j], for all j=1,...,length(Y). In case that there are multiple elements with minimal distance, the smallest index (the index of the first element with minimal distance) is returned.

Usage

1

Arguments

X

Vector of elements among which to find the closest one for each element in Y.

Y

Vector of elements for which to find the clostest element in X.

Value

Returns a vector of same length as X, with indices indicating which element in Y is closest.

Examples

1
2
3
4
5
6
X1 <- c(1,2,3)
closest.pos(X1, 1.7)
closest.pos(X1, c(1.3,2.2))

X2 <- c(2,1,3)
closest.pos(X2, 1.5)

quantspec documentation built on July 15, 2020, 1:07 a.m.