This function will bin a Spectra object by averaging every bin.ratio frequency values, and summing the corresponding intensity values. The net effect is a smoothed and smaller data set. If there are gaps in the frequency axis, each data chunk is processed separately. Note: some folks refer to binning as bucketing.

binSpectra(spectra, bin.ratio)

Arguments

spectra

An object of S3 class Spectra to be binned.

bin.ratio

An integer giving the binning ratio, that is, the number of points to be grouped together into one subset of data.

Value

An object of S3 class Spectra.

Details

If the frequency range is not divisible by bin.ratio to give a whole number, data points are removed from the beginning of the frequency data until it is, and the number of data points removed is reported at the console. If there are gaps in the data where frequencies have been removed, each continuous piece is sent out and binned separately (by binSpectra).

Author

Bryan A. Hanson (DePauw University)

Examples


data(metMUD1)
sumSpectra(metMUD1)
#>
#>  metMUD1: cntrl + trmt 4 non-correlated metabolites
#>
#> 	There are 20 spectra in this set.
#> 	The y-axis unit is intensity.
#>
#> 	The frequency scale runs from
#> 	5 to 0 ppm
#> 	There are 1500 frequency values.
#> 	The frequency resolution is
#> 	0.003335557 ppm/point.
#>
#>
#> 	The spectra are divided into 2 groups:
#>
#>   group no. color symbol alt.sym
#> 1 Cntrl  10 black      1       c
#> 2  Trmt  10   red     19       t
#>
#>
#> *** Note: this is an S3 object
#> of class 'Spectra'
res <- binSpectra(metMUD1, bin.ratio = 4)
sumSpectra(res)
#>
#>  metMUD1: cntrl + trmt 4 non-correlated metabolites
#>
#> 	There are 20 spectra in this set.
#> 	The y-axis unit is intensity.
#>
#> 	The frequency scale runs from
#> 	4.994997 to 0.005003336 ppm
#> 	There are 375 frequency values.
#> 	The frequency resolution is
#> 	0.01334223 ppm/point.
#>
#>
#> 	The spectra are divided into 2 groups:
#>
#>   group no. color symbol alt.sym
#> 1 Cntrl  10 black      1       c
#> 2  Trmt  10   red     19       t
#>
#>
#> *** Note: this is an S3 object
#> of class 'Spectra'