Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

match.closest

Relaxed Value Matching


Description

match.closest returns a vector of the positions of (first) matches its first arguments in its second. In contrast to the similar match it just accept numeric arguments but has an additional tolerance argument that allows relaxed matching.

Usage

match.closest(x, table, tolerance = Inf, nomatch = NA_integer_)

Arguments

x

numeric, the values to be matched.

table

numeric, the values to be matched against. In contrast to match table has to be sorted in increasing order.

tolerance

numeric, accepted tolerance. Use Inf to match without restrictions. Could be of length one or the same length as table.

nomatch

numeric, if the difference between the value in x and table is larger than tolerance nomatch is returned. Has to be of length one.

Value

An integer vector of the same length as x giving the closest position in table of the first match or nomatch if there is no match.

See Also

Examples

library("MALDIquant")
match.closest(c(1.1, 1.4, 9.8), 1:10)
# [1]  1  1 10
match.closest(c(1.1, 1.4, 9.8), 1:10, tolerance=0.25)
# [1]  1 NA 10
match.closest(c(1.1, 1.4, 9.8), 1:10, tolerance=0.25, nomatch=0)
# [1]  1  0 10

## this function is most useful if you want to subset an intensityMatrix
## by a few (reference) peaks

## create an example intensityMatrix
im <- matrix(1:10, nrow=2, dimnames=list(NULL, 1:5))
attr(im, "mass") <- 1:5
im
#      1 2 3 4  5
# [1,] 1 3 5 7  9
# [2,] 2 4 6 8 10
# attr(,"mass")
# [1] 1 2 3 4 5

## reference peaks
ref <- c(2.2, 4.8)

im[, match.closest(ref, attr(im, "mass"), tolerance=0.25, nomatch=0)]
#      2  5
# [1,] 3  9
# [2,] 4 10

MALDIquant

Quantitative Analysis of Mass Spectrometry Data

v1.19.3
GPL (>= 3)
Authors
Sebastian Gibb [aut, cre] (<https://orcid.org/0000-0001-7406-4443>), Korbinian Strimmer [ths] (<https://orcid.org/0000-0001-7917-2056>)
Initial release
2019-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.