[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  cut: Convert Numeric to Factor

##  Description

` cut ` divides the range of ` x ` into intervals and codes the values in ` x
` according to which interval they fall. The leftmost interval corresponds to
level one, the next leftmost to level two and so on.

##  Usage

    
    
    cut(x, …)
    
    # S3 method for default
    cut(x, breaks, labels = NULL,
        include.lowest = FALSE, right = TRUE, dig.lab = 3,
        ordered_result = FALSE, …)

##  Arguments

x

a numeric vector which is to be converted to a factor by cutting.

breaks

either a numeric vector of two or more unique cut points or a single number
(greater than or equal to 2) giving the number of intervals into which ` x `
is to be cut.

labels

labels for the levels of the resulting category. By default, labels are
constructed using ` "(a,b]" ` interval notation. If ` labels = FALSE ` ,
simple integer codes are returned instead of a factor.

include.lowest

logical, indicating if an ‘x[i]’ equal to the lowest (or highest, for ` right
= FALSE ` ) ‘breaks’ value should be included.

right

logical, indicating if the intervals should be closed on the right (and open
on the left) or vice versa.

dig.lab

integer which is used when labels are not given. It determines the number of
digits used in formatting the break numbers.

ordered_result

logical: should the result be an ordered factor?

…

further arguments passed to or from other methods.

##  Value

A ` [ factor ](/link/factor?package=base&version=3.6.2) ` is returned, unless
` labels = FALSE ` which results in an integer vector of level codes.

Values which fall outside the range of ` breaks ` are coded as ` NA ` , as are
` NaN ` and ` NA ` values.

##  Details

When ` breaks ` is specified as a single number, the range of the data is
divided into ` breaks ` pieces of equal length, and then the outer limits are
moved away by 0.1% of the range to ensure that the extreme values both fall
within the break intervals. (If ` x ` is a constant vector, equal-length
intervals are created, one of which includes the single value.)

If a ` labels ` parameter is specified, its values are used to name the factor
levels. If none is specified, the factor level labels are constructed as `
"(b1, b2]" ` , ` "(b2, b3]" ` etc. for ` right = TRUE ` and as ` "[b1, b2)" `
, … if ` right = FALSE ` . In this case, ` dig.lab ` indicates the minimum
number of digits should be used in formatting the numbers ` b1 ` , ` b2 ` , ….
A larger value (up to 12) will be used if needed to distinguish between any
pair of endpoints: if this fails labels such as ` "Range3" ` will be used.
Formatting is done by ` [ formatC ](/link/formatC?package=base&version=3.6.2)
` .

The default method will sort a numeric vector of ` breaks ` , but other
methods are not required to and ` labels ` will correspond to the intervals
after sorting.

As from  R  3.2.0, ` getOption("OutDec") ` is consulted when labels are
constructed for ` labels = NULL ` .

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ split ](/link/split?package=base&version=3.6.2) ` for splitting a variable
according to a group factor; ` [ factor
](/link/factor?package=base&version=3.6.2) ` , ` [ tabulate
](/link/tabulate?package=base&version=3.6.2) ` , ` [ table
](/link/table?package=base&version=3.6.2) ` , ` [ findInterval
](/link/findInterval?package=base&version=3.6.2) ` .

` [ quantile ](/link/quantile?package=base&version=3.6.2) ` for ways of
choosing breaks of roughly equal content (rather than length).

` [ .bincode ](/link/.bincode?package=base&version=3.6.2) ` for a bare-bones
version.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rd