matchClosest: matchClosest

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

View source: R/matchClosest.R

Description

Find index in b that is closest to a.

Usage

1
2
3
matchClosest(a, b, maxAbsDiff = Inf, isSortedA = FALSE, 
    isSortedB = FALSE, allFiniteB = FALSE, chunkSize = round(length(b)/length(a) * 
        1.6))

Arguments

a

numeric vector

b

numeric vector

maxAbsDiff

if maximum difference between best b and a[i] is larger than this, return NA for index i

isSortedA

if TRUE assures that A is sorted to speed up

isSortedB

if TRUE assures that B is sorted to speed up

allFiniteB

if TRUE assures that B contains only finite entries to speed up

chunkSize

length of the vector to calculate difference for each point in a

Details

For each a_i the c_i=j will be selected so that b_j is closest to a_i among all b If a_i is not finite, then c_i is NA

Value

vector of length of a, with each element holding an index from b

Author(s)

Thomas Wutzler

See Also

twMisc

Examples

1
2
3
4
5
6
7
8
a = seq(0,1,length.out=11)
b = sort(runif(length(a)))
#mtrace(matchClosest)
c = matchClosest(a,b,isSortedA=TRUE,isSortedB=TRUE)

plot(b~a)
points(b[c]~a, col="red", pch=2)
abline(0,1)

twMisc documentation built on May 2, 2019, 6:11 p.m.