breaks_on_binSize: Generate breaks for binning using a defined bin size.

View source: R/functions-binning.R

breaks_on_binSizeR Documentation

Generate breaks for binning using a defined bin size.

Description

Defines breaks for binSize sized bins for values ranging from fromX to toX.

Usage

breaks_on_binSize(fromX, toX, binSize)

Arguments

fromX

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

toX

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

binSize

numeric(1) defining the size of a bin.

Details

This function creates breaks for bins of size binSize. The function ensures that the full data range is included in the bins, i.e. the last value (upper boundary of the last bin) is always equal toX. This however means that the size of the last bin will not always be equal to the desired bin size. See examples for more details and a comparisom to R's seq function.

Value

A numeric vector 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_nBins()

Examples

## Define breaks with a size of 0.13 for a data range from 1 to 10:
breaks_on_binSize(1, 10, 0.13)
## The size of the last bin is however larger than 0.13:
diff(breaks_on_binSize(1, 10, 0.13))
## If we would use seq, the max value would not be included:
seq(1, 10, by = 0.13)

## In the next example we use binSize that leads to an additional last bin with
## a smaller binSize:
breaks_on_binSize(1, 10, 0.51)
## Again, the max value is included, but the size of the last bin is < 0.51.
diff(breaks_on_binSize(1, 10, 0.51))
## Using just seq would result in the following bin definition:
seq(1, 10, by = 0.51)
## Thus it defines one bin (break) less.

sneumann/xcms documentation built on Nov. 3, 2024, 10:33 p.m.