mclosest | R Documentation |
The mclosest
function calculates the closest rows between two matrices
(or data frames) considering pairwise differences between values in columns
of x
and table
. It returns the index of the closest row in table
for
each row in x
.
mclosest(x, table, ppm = 0, tolerance = Inf)
x |
|
table |
|
ppm |
|
tolerance |
|
If, for a row of x
, two rows of table
are closest only the index of first
row will be returned.
For both the tolerance
and ppm
arguments, if their length is different to
the number of columns of x
and table
, the input argument will be
replicated to match it.
integer
vector of indices indicating the closest row of table
for
each row of x
. If no suitable match is found for a row in x
based on the
specified tolerance
and ppm
, the corresponding index is set to NA
.
Philippine Louail
x <- data.frame(a = 1:5, b = 3:7)
table <- data.frame(c = c(11, 23, 3, 5, 1), d = c(32:35, 45))
## Get for each row of `x` the index of the row in `table` with the smallest
## difference of values (per column)
mclosest(x, table)
## If the absolute difference is larger than `tolerance`, return `NA`. Note
## that the tolerance value of `25` is used for difference for each pairwise
## column in `x` and `table`.
mclosest(x, table, tolerance = 25)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.