Description Usage Arguments Value Author(s) See Also Examples
match_dbl
returns a vector of the positions of (first) matches
of its first argument in its second.
1 2 | match_dbl(x, table, nomatch = NA_integer_,
tolerance = sqrt(.Machine$double.eps))
|
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. |
An integer vector giving the position in table of the first match if there is a match, otherwise nomatch.
Dominik Mueller
%in_dbl%
for an numerical analog to
%in%
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.