Learn R Programming

ChemoSpec (version 3.0-1)

removeFreq: Remove Frequencies from a Spectra Object

Description

This function removes specified frequencies from a "Spectra" object. For instance, one might want to remove regions lacking any useful information (to reduce the data size), or remove regions with large interfering peaks (e.g. the water peak in 1H NMR).

Usage

removeFreq(spectra, rem.freq)

Arguments

spectra
An object of S3 class "Spectra" from which to remove selected frequencies.
rem.freq
A valid R statement describing the frequencies to be removed. This must comply with Comparison and Logic. See the examples below for common usage.

Value

  • An object of S3 class "Spectra".

Details

rem.freq can be any valid R statement that leads to a vector of logicals. In the examples below, the | and & operators seem backward in some sense, but R evaluates them one at a time and combines the result to give the required output.

References

https://github.com/bryanhanson/ChemoSpec

Examples

Run this code
data(CuticleIR)
sumSpectra(CuticleIR) # note the frequency range & existing gap
# remove frequencies from one end:
newIR <- removeFreq(CuticleIR, rem.freq = CuticleIR$freq > 3500)
# remove frequencies from both ends at once:
newIR <- removeFreq(CuticleIR, rem.freq = CuticleIR$freq > 3500
| CuticleIR$freq < 800)
# remove frequencies from the middle:
newIR <- removeFreq(CuticleIR, rem.freq = CuticleIR$freq > 800
& CuticleIR$freq < 1000)

# The logic of this last one is as follows.  Any values
# that are TRUE will be removed.
values <- 1:7
values > 2
values < 6
values > 2 & values < 6

# after any of these, inspect the results:
sumSpectra(newIR)
check4Gaps(newIR$freq, newIR$data[1,], plot = TRUE)

Run the code above in your browser using DataLab