Learn R Programming

MALDIquant (version 1.7)

movingAverage: Moving Average Smoothing Filter

Description

This function runs a simple 2-side moving average.

Usage

movingAverage(y, halfWindowSize=2)

Arguments

y
intensity values
halfWindowSize
half window size. The resulting window reaches from mass[currentIndex-halfWindowSize] to mass[currentIndex+halfWindowSize] (window size is 2*halfWindowSize+1).

Value

  • double, a smoothed intensity vector.

See Also

savitzkyGolay, MassSpectrum, transformIntensity,AbstractMassObject-method

Examples

Run this code
## load library
library("MALDIquant")

## 5 point moving average
movingAverage(rep(1:5, times=2), halfWindowSize=2)
# 3 3 3  3  3  3  3  3 3 3

## 9 point moving average
movingAverage(rep(1:5, times=2), halfWindowSize=4)
# 2.778 2.778 2.778 2.778 2.778 3.222 3.222 3.222 3.222 3.222

## load example data
data("fiedler2009subset", package="MALDIquant")

## smooth spectra
s <- transformIntensity(fiedler2009subset, movingAverage, halfWindowSize=2)

Run the code above in your browser using DataLab