quantcut {gregmisc}R Documentation

Create a Factor Variable Using the Quantiles of a Continuous Variable

Description

Create a factor variable using the quantiles of a continous variable.

Usage

quantcut(x, q=c(0, 1/4, 2/4, 3/4, 4/4), na.rm=TRUE, include.lowest=TRUE, ...)

Arguments

x Continous variable.
q Vector of quantiles used for creating groups. Defaults to c(0, 1/4, 2/4, 3/4, 4/4). See quantile for details.
na.rm Boolean indicating whether missing values should be removed when computing quantiles. Defaults to TRUE.
include.lowest Boolean indicating whether values exactly equal to the lowest specified quantile be included in the lowest group. See cut for details.
... Optional arguments passed to cut.

Details

This function is simply a uses quantile to obtaine the quantiles of x, then calls cut to create a factor variable using the quantiles for cut points.

Value

Factor variable with one level for each quantile interval given by q.

Author(s)

Gregory R. Warnes Gregory_R_Warnes@groton.pfizer.com

See Also

cut, quantile

Examples


  x <- rnorm(1000)
  quants <- quantcut( x )
  table(quants)

[Package Contents]