View source: R/cut_with_bin_labels.R
cut_with_bin_labels | R Documentation |
cut
using endpoints as bin labels bin labelsUse endpoints as bin labels with cut
. The only difference between
this function and cut
, is that this function will label the
levels based on the endpoints if labels
are specified as either
"left" or "right". For more information, see cut
cut_with_bin_labels(
x,
breaks,
labels = NULL,
include.lowest = FALSE,
right = TRUE,
dig.lab = 3,
ordered_result = FALSE,
...
)
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. If 'labels = "left"' then the labels will be a numeric verctor with the left endpoints. If 'labels = "right"' then the labels will be a numeric verctor with the right endpoints. |
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. Default is
|
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. |
cut()
, ggplot2::cut_interval()
,
ggplot2::cut_width()
, ggplot2::cut_number()
data(mtcars)
breaks <- seq(from = 0, to = max(mtcars$hp) + 10, by = 10)
dt <- data.table(
hp = mtcars$hp,
bin.cut.default = cut(mtcars$hp, breaks = breaks),
bin.left.endpoint = cut_with_bin_labels(
mtcars$hp, breaks = breaks, labels = "left"),
bin.right.endpoint = cut_with_bin_labels(
mtcars$hp, breaks = breaks, labels = "right")
)
dt %>% print
# Using `right` == FALSE
dt2 <- data.table(
hp = mtcars$hp,
bin.cut.default = cut(mtcars$hp, breaks = breaks, right = FALSE),
bin.left.endpoint = cut_with_bin_labels(
mtcars$hp, breaks = breaks, labels = "left", right = FALSE),
bin.right.endpoint = cut_with_bin_labels(
mtcars$hp, breaks = breaks, labels = "right", right = FALSE)
)
dt2 %>% print()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.