trapz: Trapezoidal integration of mass-spec retention time /...

View source: R/extraHelperFunctions.R

trapzR Documentation

Trapezoidal integration of mass-spec retention time / intensity values

Description

Performs a trapezoidal Riemann sum to calculate the area under the curve for mass-spectrometry data. Accepts a vector of retention times and the associated intensities and returns the area.

Usage

trapz(rts, ints, baseline = "none")

Arguments

rts

A numeric vector of retention times across an MS peak. Should be monotonically increasing and without duplicates or will throw a warning.

ints

A numeric vector of measured intensities across an MS peak

baseline

A length-1 character vector of either "none" (the default), "square", or "trapezoid".

Value

A length-1 numeric value representing the area under the curve

Examples

trapz(1:10, 1:10)
trapz(1:10, 10:1)

trapz(1:10, 11:20)
trapz(1:10, 11:20, baseline="square")
trapz(1:10, 11:20, baseline="trapezoid")

x_vals <- seq(-2, 2, length.out=100)
trapz(x_vals, dnorm(x_vals))

x_vals <- seq(0, pi/2, length.out=100)
trapz(x_vals, cos(x_vals))

RaMS documentation built on Oct. 9, 2024, 9:06 a.m.