Learn R Programming

RaMS (version 1.4.3)

trapz: 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")

Value

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

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".

Examples

Run this code
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))

Run the code above in your browser using DataLab