match_dbl: A version of 'match' working exclusively on numeric data.

Description Usage Arguments Value Author(s) See Also Examples

Description

match_dbl returns a vector of the positions of (first) matches of its first argument in its second.

Usage

1
2
match_dbl(x, table, nomatch = NA_integer_,
  tolerance = sqrt(.Machine$double.eps))

Arguments

x

A numeric vector with the values to be matched.

table

A numeric vector with the values to be matched against.

nomatch

An integer as the value to be returned in the case when no match is found.

numeric

scalar >= 0. Differences smaller than 'tolerance' are not recognized. The default value is close to 1.5e-8.

Value

An integer vector giving the position in table of the first match if there is a match, otherwise nomatch.

Author(s)

Dominik Mueller

See Also

%in_dbl% for an numerical analog to %in%

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# generate some random numeric data
set.seed(123)
table <- runif(1000L)
table <- sample(c(table, table)) # 'table' now contains duplicates
x <- sample(table, 100L)

m1 <- match(x, table)
m1_dbl <- match_dbl(x, table)
identical(m1, m1_dbl) # TRUE according to expectation

microbenchmark::microbenchmark(match(x, table),
                               match_dbl(x, table)) # speed is fine

# minimally disturb x
x <- x + runif(n = length(x), min = -1e-10, max = 1e-10)

identical(m1, match(x, table)) # now FALSE 
identical(m1_dbl, match_dbl(x, table)) # still TRUE
identical(m1_dbl, match_dbl(x, table, tolerance = 1e-11)) # also FALSE now

DominikMueller64/dmisc documentation built on May 6, 2019, 2:52 p.m.