Using base/stats functions cut() and quantile().
Usage
quantile_cut(
x,
groups,
y = NULL,
na.rm = TRUE,
group.names = NULL,
ordered.f = FALSE,
inc.outs = FALSE,
detail.list = FALSE,
probs = NULL,
right = TRUE
)
Arguments
- x
Variable to cut.
- groups
Number of groups of equal size.
- y
alternative vector to draw quantile cuts from. Limits has to be within x. Default is NULL.
- na.rm
Remove NA's. Default is TRUE.
- group.names
Names of groups to split to. Default is NULL, giving intervals as names.
- ordered.f
Set resulting vector as ordered. Default is FALSE.
- inc.outs
Flag to include min(x) and max(x) as borders in case of y!=NULL.
- detail.list
flag to include details or not
- probs
Supply exact probs directly to 'quantile()' for clusters of different sizes. If provided, then group is ignored. Default is NULL.
- right
logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa (used in 'cut()').
Examples
aa <- as.numeric(sample(1:1000, 2000, replace = TRUE))
x <- 1:450
y <- 6:750
summary(quantile_cut(aa, groups = 4, detail.list = FALSE)) ## Cuts quartiles
#> [1,245] (245,488] (488,746] (746,1e+03]
#> 500 502 499 499
summary(quantile_cut(aa, probs = c(0, .2, .5), detail.list = FALSE))
#> [1,194] (194,488] NA's
#> 400 602 998