Learn R Programming

RcmdrMisc (version 2.10.2)

binVariable: Bin a Numeric Variable

Description

Bin a Numeric Variable

Usage

binVariable(
  x,
  bins = 4,
  method = c("intervals", "proportions", "natural"),
  labels = FALSE
)

Value

A factor.

Arguments

x

numeric variable to be binned.

bins

number of bins.

method

one of "intervals" for equal-width bins; "proportions" for equal-count bins; "natural" for cut points between bins to be determined by a k-means clustering.

labels

if FALSE, numeric labels will be used for the factor levels; if NULL, the cut points are used to define labels; otherwise a character vector of level names.

Author

Dan Putler, slightly modified by John Fox (5 Dec 04 & 5 Mar 13) with the original author's permission.

Details

Create a factor dissecting the range of a numeric variable into bins of equal width, (roughly) equal frequency, or at "natural" cut points. The cut function is used to create the factor.

See Also

Examples

Run this code
summary(binVariable(rnorm(100), method="prop", labels=letters[1:4]))

Run the code above in your browser using DataLab