Learn R Programming

ChemoSpec (version 4.4.97)

check4Gaps: Check for Missing Values (Gaps) in a Spectra Object

Description

This function may be used with a Spectra object to see if there are any gaps or discontinuities in the frequency axis. Gaps may arise when unwanted frequencies are removed (e.g, water peaks in 1H NMR, or uninteresting regions in any kind of spectroscopy). As written, it can be used to check for gaps in any appropriate numeric vector. A plot of the gaps is optional.

Usage

check4Gaps(x, y = NULL, tol = 0.01, plot = FALSE, silent = FALSE, ...)

Arguments

x

A numeric vector to be checked for gaps.

y

An optional vector of y-values which correspond to the x values. Only needed if plot = TRUE.

tol

A number indicating the tolerance for checking to see if the step between successive x values are the same. Depending upon how the x values are stored and rounded, you may need to change the value of tol to avoid flagging trivial "gaps".

plot

Logical indicating if a plot of the gaps should be made. If TRUE, y must be provided. The plot is labeled consistent with calling this function on a Spectra object.

silent

Logical indicating a "no gap" condition (return value is FALSE) should not be reported to the console. Important because check4Gaps is called iteratively by other functions.

Other parameters to be passed to the plot routines if plot = TRUE, e.g. xlim.

Value

A data frame giving the data chunks found, with one chunk per line. Also a plot if requested. In the event there are no gaps found, FALSE is returned.

beg.freq

The first frequency value in a given data chunk.

end.freq

The last frequency value in a given data chunk.

size

The length (in frequency units) of the data chunk.

beg.indx

The index of the first frequency value in the data chunk.

eng.indx

The index of the last frequency value in the data chunk.

Details

The basic procedure is to compare x[n + 1] - x[n] for successive values of n. When this value jumps, there is a gap which is flagged. beg.indx and end.indx will always be contiguous as indices must be; it is the x values that jump or have the gap. The indices are provided as they are more convenient in some programming contexts. If not assigned, the result appears at the console.

References

https://github.com/bryanhanson/ChemoSpec

Examples

Run this code
# NOT RUN {
x <- seq(from = 5, to = 12, by = 0.1)
remove <- c(8:11, 40:45); x <- x[-remove]
gaps <- check4Gaps(x)

data(SrE.IR)
newIR <- removeFreq(SrE.IR, rem.freq = SrE.IR$freq > 1800 & SrE.IR$freq < 2500)
check4Gaps(newIR$freq, newIR$data[1,], plot = TRUE)

# }

Run the code above in your browser using DataLab