# NOT RUN {
set.seed(123)
x <- sample(1:10, size = 50, replace = TRUE)
table(x)
# by default, at median
table(data_cut(x))
# into 3 groups, based on distribution (quantiles)
table(data_cut(x, split = "quantile", n_groups = 3))
# into 3 groups, user-defined break
table(data_cut(x, split = c(3, 5)))
set.seed(123)
x <- sample(1:100, size = 500, replace = TRUE)
# into 5 groups, try to recode into intervals of similar length,
# i.e. the range within groups is the same for all groups
table(data_cut(x, split = "equal_length", n_groups = 5))
# into 5 groups, try to return same range within groups
# i.e. 1-20, 21-40, 41-60, etc. Since the range of "x" is
# 1-100, and we have a range of 20, this results into 5
# groups, and thus is for this particular case identical
# to the previous result.
table(data_cut(x, split = "equal_range", range = 20))
# return factor with value labels instead of numeric value
set.seed(123)
x <- sample(1:10, size = 30, replace = TRUE)
data_cut(x, "equal_length", n_groups = 3)
data_cut(x, "equal_length", n_groups = 3, labels = c("low", "mid", "high"))
# }
Run the code above in your browser using DataLab