Learn R Programming

ChemoSpec (version 3.0-1)

check4Gaps: Check for Missing Values (Gaps)

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. Not normally called directly by the user, but may be (see examples). 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 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
plot
Logical indicating if a plot of the gaps should be made. If TRUE, y must be provided.
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.freqThe first frequency value in a given data chunk.
  • end.freqThe last frequency value in a given data chunk.
  • sizeThe length (in frequency units) of the data chunk.
  • beg.indxThe index of the first frequency value in the data chunk.
  • eng.indxThe 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
x <- seq(from = 5, to = 12, by = 0.1)
remove <- 40:45; x <- x[-remove]
check4Gaps(x) # really simple
gaps <- check4Gaps(x) # save the result for later use
data(CuticleIR) # has a gap, let's find it and display it
check4Gaps(CuticleIR$freq, CuticleIR$data[1,], plot = TRUE)

Run the code above in your browser using DataLab