matchWithPpm: Match values allowing a certain difference in ppm

Description Usage Arguments Value Author(s) Examples

View source: R/mass-utility-functions.R

Description

Match numeric values in x against values in y and return indices of all matches of x in y allowing differences between the values specified with parameter ppm (part per million).

Usage

1
matchWithPpm(x, y, ppm = 0)

Arguments

x

numeric with input values to match in y. Supposed to be a shorter numeric than y.

y

numeric with values to match x against.

ppm

numeric(1) defining the allowed difference between values to be still considered a match. Differences smaller than +/- ppm are accepted.

Value

list with integer representing the index in y where each element in x matches (given the provided ppm).

Author(s)

Johannes Rainer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
yvals <- abs(rnorm(1000))
yvals[123] <- yvals[2] - yvals[2] * 10 * 1e-6
yvals[124] <- yvals[2] + yvals[2] * 10 * 1e-6
yvals[125] <- yvals[2] + yvals[2] * 12 * 1e-6
xvals <- yvals[c(2, 3, 3, 20, 21, 20)]
xvals[2] <- xvals[2] + (10 * xvals[2] / 1e6)
xvals[3] <- xvals[3] - (10 * xvals[3] / 1e6)
xvals[6] <- xvals[6] + (12 * xvals[6] / 1e6)

## Perfect matches:
matchWithPpm(xvals, yvals)

## Match allowing +/- 10ppm difference
matchWithPpm(xvals, yvals, ppm = 10)

## Match allowing +/- 20ppm difference
matchWithPpm(xvals, yvals, ppm = 20)

michaelwitting/CompoundDb documentation built on April 29, 2020, 8:42 p.m.