Learn R Programming

easyr (version 0.5-11)

binbyvol: Bin by Volume

Description

Bins a numerical column according to another numerical column's volume. For example if I want to bin a column "Age" (of people) into 10 deciles according to "CountofPeople" then I will get Age breakpoints returned by my function such that there is 10 This function handles NA's as their own separate bin, and handles any special values you want to separate out. Author: Scott Sobel. Tech Review: Bryce Chamberlain.

Usage

binbyvol(df, groupby, vol, numbins)

Value

Age breakpoints returned by my function such that there is 10

Arguments

df

(Data Frame) Your data.

groupby

(Character) Name of the column you'll create cuts in. Must be the character name of a numeric column.

vol

(Character) Name of the column for which which each cut will have an equal percentage of volume.

numbins

Number of bins to use.

Examples

Run this code
# bin Sepal.Width according to Sepal.Length.
iris$bin <- binbyvol(iris, 'Sepal.Width', 'Sepal.Length', 5)

# check the binning success.
aggregate( Sepal.Length ~ bin, data = iris, sum )

Run the code above in your browser using DataLab