TITLE(cut @@ Convert Numeric to Factor )
USAGE(
cut(x, breaks, labels=NULL, right=TRUE, dig.lab=3)
)
ALIAS(cut)
ARGUMENTS(
ARG(x@@ a numeric vector which is to be converted to a factor by cutting.)
ARG(break @@ either a vector of cut points or number
giving the number of intervals which LANG(x) is to be
cut into.)
ARG(labels @@ labels for the levels of the resulting category. By default
labels are constructed using "\(a,b]" interval notation.).
ARG(right @@ logical, indicating if the intervals should closed on the
right (and open on the left) or vice versa.)
ARG(dig.lab @@ integer which is used when labels are not given. It
determines the number of digits used in formatting the break numbers.)
)
VALUE(
LANG(cut) divides the range of LANG(x) into intervals
and codes the values in LANG(x) according to which
interval they fall.
The leftmost interval corresponds to level one,
the next leftmost to level two and so on.
If a LANG(labels) parameter is specified, its values are used
to name the factor levels. If none is specified, the factor
level labels are constructed as LANG("\(b1, b2]"), LANG("\(b2, b3]") 
etc. for LANG(right=TRUE) and as LANG("[b1, b2\)"), LDOTS if
LANG(right=FALSE).
In this case, LANG(dig.lab) indicates how many digits should be used in
formatting the numbers LANG(b1), LANG(b2), LDOTS.
)
SEEALSO(
LANG(LINK(split)) for splitting a variable according to a group factor;
LANG(LINK(factor)), LANG(LINK(tabulate)), LANG(LINK(table)).
)
EXAMPLES(
cut(rep(1,5),4)#-- dummy
tx0 <- c(9, 4, 6, 5, 3, 10, 5, 3, 5)
x <- rep(0:8, tx0)
tx <- table(x)
all(tx == tx0)
table( cut(x, b = 8))
table( cut(x, br = 3*(-2:5)))
table( cut(x, br = 3*(-2:5), right = F))
BLANK
##--- some values OUTSIDE the breaks :
table(cx  <- cut(x, br = 2*(0:4)))
table(cxl <- cut(x, br = 2*(0:4), right = F))
which(is.na(cx));  x[is.na(cx)]  #-- the first 9  values  0
which(is.na(cxl)); x[is.na(cxl)] #-- the last  5  values  8
BLANK
## Label construction:
y <- rnorm(100)
table(cut(y, breaks = pi/3*(-3:3)))
table(cut(y, breaks = pi/3*(-3:3), dig.lab=4))
BLANK
table(cut(y, breaks =  1*(-3:3), dig.lab=4))# extra digits don't "harm" here
table(cut(y, breaks =  1*(-3:3), right = F))#- the same, since no exact INT!
)
