Check for Discontinuities (Gaps) in a Vector & Optionally Make a Plot
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.
check4Gaps(x, y = NULL, silent = FALSE, tol = NULL, ...)
x |
A numeric vector to be checked for gaps. |
y |
An optional vector of |
silent |
Logical indicating a "no gap" message
should not be reported to the console. Important because
|
tol |
A number indicating the tolerance for checking to see if the step
between successive |
... |
Other parameters to be passed to the plot routines if
|
A data frame giving the data chunks found, with one chunk per row. Also a plot if y is provided. In the event there are no gaps found, a data frame with one row is returned. The data frame has columns as follows:
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. |
end.indx |
The index of the last frequency value in the data chunk. |
Bryan A. Hanson, DePauw University.
sumSpectra
which make extensive use of this function.
x <- seq(0, 2 * pi, 0.1) y <- sin(x) remove <- c(8:11, 40:45) x <- x[-remove] y <- y[-remove] gaps <- check4Gaps(x, tol = 0.11) # tol just larger than orig spacing gaps gaps <- check4Gaps(x, y, tol = 0.11) # show a plot if y given
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.