breaks_on_nBins: Generate breaks for binning

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/functions-binning.R

Description

Calculate breaks for same-sized bins for data values from fromX to toX.

Usage

1
breaks_on_nBins(fromX, toX, nBins, shiftByHalfBinSize = FALSE)

Arguments

fromX

numeric(1) specifying the lowest value for the bins.

toX

numeric(1) specifying the largest value for the bins.

nBins

numeric(1) defining the number of bins.

shiftByHalfBinSize

Logical indicating whether the bins should be shifted left by half bin size. This results centered bins, i.e. the first bin being centered at fromX and the last around toX.

Details

This generates bins such as a call to seq(fromX, toX, length.out = nBins) would. The first and second element in the result vector thus defines the lower and upper boundary for the first bin, the second and third value for the second bin and so on.

Value

A numeric vector of length nBins + 1 defining the lower and upper bounds of the bins.

Author(s)

Johannes Rainer

See Also

binYonX for a binning function.

Other functions to define bins: breaks_on_binSize()

Examples

1
2
3
4
## Create breaks to bin values from 3 to 20 into 20 bins
breaks_on_nBins(3, 20, nBins = 20)
## The same call but using shiftByHalfBinSize
breaks_on_nBins(3, 20, nBins = 20, shiftByHalfBinSize = TRUE)

xcms documentation built on Nov. 8, 2020, 5:13 p.m.