Description Usage Arguments Details Value Examples
cut divides the range of x
into intervals and codes the values in
x
according to the interval they fall into.
1 2 3 |
x |
An ordered factor which is to be cut into ordered bins. |
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 |
labels |
Labels for the levels of the resulting category. By default,
labels are constructed using |
include.lowest |
Logical, indicating if an |
right |
Logical, indicating how to create the bins. This is utilized in
two different ways based on the type of breaks argument. In the
conventional case, where a breaks vector is supplied, |
ordered_result |
Logical: should the result be an ordered factor? Note
that since the input data is ordered this argument is |
label_sep |
A single or short character string used to generate labels for the intervals e.g. the default value of "-" will result in labels like a-c d-g i-z etc. |
... |
Further arguments to be passed to or from other methods,
in particular to |
Note that the dig.lab
argument from cut.default
, is
replaced for cut.ordered
by a new argument: label_sep
. Also
note that unlike cut.default
, here include.lowest
defaults to TRUE
, since this is more intuitive for the class
ordered
. Finally, since the input for cut.ordered
is of class
ordered
, this is the default output as well. This contrasts with
cut.default
, which produces an unordered output by default.
A factor is returned, unless labels = FALSE
which results in
an integer vector of level codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | some_letters <- cfactor(letters, ordered = TRUE)
# bin letters into two groups
cut(some_letters, breaks = c("a", "q", "z"),
labels = c("beginning of the alphabet", "the rest of the alphabet"),
right = TRUE, include.lowest = TRUE)
# alter separator
cut(some_letters, breaks = 20, label_sep = " to ")
## Not run:
# warnings
## missing values created
cut(some_letters, breaks = c("a", "g"), label_sep = " to ")
## bins of width 1
cut(some_letters, breaks = 20)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.