binning: Binning

Description Usage Arguments Value Author(s) See Also Examples

Description

Aggregate values in x for bins defined on y: all values in x for values in y falling into a bin (defined on y) are aggregated with the provided function FUN.

Usage

1
2
3
4
5
6
7
bin(
  x,
  y,
  size = 1,
  breaks = seq(floor(min(y)), ceiling(max(y)), by = size),
  FUN = max
)

Arguments

x

numeric with the values that should be aggregated/binned.

y

numeric with same length than x with values to be used for the binning.

size

numeric(1) with the size of a bin.

breaks

numeric defining the breaks (bins).

FUN

function to be used to aggregate values of x falling into the bins defined by breaks.

Value

list with elements x (aggregated values of x) and mids (the bin mid points).

Author(s)

Johannes Rainer, Sebastian Gibb

See Also

Other grouping/matching functions: closest()

Examples

1
2
3
4
5
6
7
8
9
## Define example intensities and m/z values
ints <- abs(rnorm(20, mean = 40))
mz <- seq(1:length(ints)) + rnorm(length(ints), sd = 0.001)

## Bin intensities by m/z bins with a bin size of 2
bin(ints, mz, size = 2)

## Repeat but summing up intensities instead of taking the max
bin(ints, mz, size = 2, FUN = sum)

MsCoreUtils documentation built on Nov. 8, 2020, 10:59 p.m.