Learn R Programming

ir (version 0.4.1)

ir_bin: Bins infrared spectra

Description

ir_bin bins intensity values of infrared spectra into bins of a defined width or into a defined number of bins.

Usage

ir_bin(x, width = 10, new_x_type = "start", return_ir_flat = FALSE)

Value

An object of class ir (or ir_flat, if return_ir_flat = TRUE), where spectra have been binned.

Arguments

x

An object of class ir with integer wavenumber values increasing by 1.

width

An integer value indicating the wavenumber width of each resulting bin.

new_x_type

A character value denoting how new wavenumber values for the computed bins should be stored in the spectra of x after binning. Must be one of:

"start"

New wavenumbers for binned intensities are the start wavenumber value which defines the start of each bin. The default (for historical reasons).

"mean"

New wavenumbers for binned intensities are the average of the start and end wavenumber values which define the start and end of each bin.

"end"

New wavenumbers for binned intensities are the end wavenumber value which defines the end of each bin.

return_ir_flat

Logical value. If TRUE, the spectra are returned as ir_flat object.

Details

If a wavenumber value exactly matches the boundary of a bin window, the respective intensity value will be assigned to both neighboring bins.

Examples

Run this code
# new wavenumber values are the first wavenumber value for each bin
x1 <-
   ir::ir_sample_data |>
   ir_bin(width = 50, new_x_type = "start")

# new wavenumber values are the last wavenumber value for each bin
x2 <-
   ir::ir_sample_data |>
   ir_bin(width = 50, new_x_type = "mean")

# new wavenumber values are the average of the wavenumber values assigned to
# each bin
x3 <-
   ir::ir_sample_data |>
   ir_bin(width = 50, new_x_type = "end")

# compare wavenumber values for first spectra.
cbind(x1$spectra[[1]]$x, x2$spectra[[1]]$x, x3$spectra[[1]]$x)

Run the code above in your browser using DataLab