Learn R Programming

tidyvpc (version 1.5.2)

binningfunctions: Different functions that perform binning.

Description

Different functions that perform binning.

Usage

cut_at(breaks)

nearest(centers)

bin_by_ntile(nbins)

bin_by_eqcut(nbins)

bin_by_pam(nbins)

bin_by_classInt(style, nbins = NULL)

Value

Each of these functions returns a function of a single numeric vector `x` that assigns each value of `x` to a bin.

Arguments

breaks

A numeric vector of values that designate cut points between bins.

centers

A numeric vector of values that designate the center of each bin.

nbins

The number of bins to split the data into.

style

a binning style (see classIntervals for details).

Examples

Run this code

x <- c(rnorm(10, 1, 1), rnorm(10, 3, 2), rnorm(20, 5, 3))
centers <- c(1, 3, 5)
nearest(centers)(x)

breaks <- c(2, 4)
cut_at(breaks)(x)

bin_by_eqcut(nbins=4)(x)
bin_by_ntile(nbins=4)(x)

bin_by_pam(nbins=4)(x)
bin_by_classInt("pretty", nbins=4)(x)

Run the code above in your browser using DataLab