cut
Create Factor Object from Numeric Vector

Description

Creates a factor object by dividing a numeric vector into a certain number of intervals or defined ranges.

Usage

cut(x, ...)
cut.default(x, breaks, labels = NULL, include.lowest = FALSE, 
    right = TRUE, dig.lab = 3, ordered_result = FALSE, ...)
.bincode(x, breaks, right = TRUE, include.lowest = FALSE)

Arguments

x a numeric vector to divide into a factor. Missing values (NAs) are allowed.
breaks For the default method of cut, an integer or numeric vector that defines the breakpoints. A single number, 2 or more, specifies the number of equal-width intervals for x. If a vector of breakpoints is specified, the category has length(breaks)-1 groups and they correspond to data in the intervals between successive values in breaks.

For .bincode, only only the numeric vector of breakpoints, of length more than 1, is accepted.

labels a character vector that specifies a label for each interval.
  • If the labels argument is not specified (the default), the breakpoints are encoded to create the interval names in the form "(lower.limit, upper.limit]" or, if right = FALSE, "[lower.limit, upper.limit)".
  • If the labels argument is specified, the number of labels must be one fewer than number of break points.
  • If FALSE, the return value is a vector of integers instead of a factor.
  • If TRUE, it is interpreted as one label "TRUE".
include.lowest a logical value that specifies the inclusion or exclusion of an endpoint in the lowest or highest interval depending on the value of right.
  • When right = TRUE: if FALSE (the default), all intervals include the upper endpoint but not the lower endpoint. If TRUE, the lowest interval includes the lower endpoint.
  • When right = FALSE: if FALSE (the default), all intervals include the lower endpoint but not the upper endpoint. If TRUE, the highest interval includes the upper endpoint.
right a logical value. If FALSE (the default), each interval includes the lower endpoint of the internal instead of the upper endpoint. include.lowest has the opposite effect. That is, instead of having the default behavior where each interval includes the lower endpoint but not the upper endpoint, the behavior in this case is that the highest interval will include the upper endpoint.

For timeDate related classes such as positionsCalendar and timeSpan, the default is TRUE.

dig.lab an integer that is used when labels are not given. It is used to specify the number of digits to use when formatting the break numbers. The default value is 3.
ordered_result a logical value. If TRUE, the result is turned into a ordered factor before returning. The default is FALSE.
... further arguments for other methods.

Details

In either case, missing values in x create missing values in the result.
The cut function is generic.
Value
cut returns either a factor or an integer vector. .bincode returns an integer vector, the same as what cut(labels=FALSE, ...) would return.
See Also
cut.dates, table, tapply.
Examples
x <- 1:10
cut(x, 3)   # cut into 3 groups
cut(x, c(0,5,11))  # cut based on given breakpoints
cut(x, pretty(x))   # approx 5 "pretty" intervals
cut(x, c(1,5,10), right = FALSE, inc = TRUE) # cut using left intervals
Package base version 6.0.0-69
Package Index