bin: Customised Automatic Binning

Description Usage Arguments Details Note

Description

The bin function automates the binning process of all types of variables. It can create automated bins, quantile defined bins, factor defined bins and customised bins (using customised cut-off points). The function bins does the same thing as bin only without printing and plotting any outputs.

Usage

1
bin(x, y, data, type = "a", q = 0.2, cut = NULL)

Arguments

x

The desired continuous or categorical variable that needs to be binned. Name of variable must be given in quotes; "variable".

y

Binary response variable (0,1). Integer (int) is required. Name of y must not have a dot. Name of variable must be given in quotes; "variable".

data

The data frame containing the x and y variables.

type

The type of binning that will be taking place, which is also linked to what type of variable x is. The available options are:

  • "a" for automatic binning; no further action required (q and cut will be ignored).

  • "f" for factor binning; no further action required (q and cut will be ignored).

  • "q" for quantile binning; q will then define the size of the quantiles.

  • "c" for customised binning; cut will then define the size of the bins

q

If type = "q": The size of the quantiles used for binning. Default value is 0.2, which means that there will be 5 bins, each containing 20% of the data.

cut

If type = "c": A vector containing cut-off points that allows the creation of customised bins. Values chosen must be from the x variable. Default value is NULL, if unchanged, output will be automatic as if 'type = "a"'.

Details

The type is the most important argument; when it equals to "a" or "f", the arguments q and cut will become redundant. The arguments q and cut will only be taken into account when the values for type are "q" and c respectively.

Note that if type = "c" and no vector was entered for the cut argument, the function will perform automatic binning.

Note

If type = "c" and no vector was entered for the cut argument, the function will perform automatic binning.


Ehsan-F/R-Mixtape documentation built on June 24, 2020, 12:22 a.m.