Put reals and integers into specified bins, returning factors.
Put reals and integers into specified bins, returning ordered factors. Like cut
but for human use.
mcut( x, breaks, pre.lab='', mid.lab='', post.lab='', digits=getOption( 'digits')) mintcut( x, breaks=NULL, prefix='', all.levels=, by.breaks=1)
x |
(numeric vector) What to bin– will be coerced to integer for |
breaks |
(numeric vector) LH end of each bin– should be increasing. Values of |
prefix, pre.lab |
(string) What to prepend to the factor labels– e.g. "Amps" if your original data is about Amps. |
mid.lab |
"units" to append to numeric vals inside factor labels. Tends to make the labels harder to read; try using |
post.lab |
(string) What to append to the factor labels. |
digits |
(integer) How many digits to put into the factor labels. |
all.levels |
if FALSE, omit factor levels that don't occur in |
by.breaks |
for |
Values of x
below breaks[1]
will end up as NAs. For mintcut
, factor labels (well, the bit after the prefix
) will be of the form "2-7" or "3" (if the bin range is 1) or "8+" (for last in range). For mcut
, labels will look like this (apart from the pre.lab
and post.lab
bits): "[<0.25]" or "[0.25,0.50]" or "[>=0.75]".
set.seed( 1) mcut( runif( 5), c( 0.25, 0.5, 0.75)) # [1] [0.25,0.50] [0.25,0.50] [0.50,0.75] [>=0.75] [<0.25] # Levels: [<0.25] [0.25,0.50] [0.50,0.75] [>=0.75] mcut( runif( 5), c( 0.25, 0.5, 0.75), pre.lab='A', post.lab='B', digits=1) # [1] A[>=0.8]B A[>=0.8]B A[0.5,0.8]B A[0.5,0.8]B A[<0.2]B # Levels: A[<0.2]B A[0.2,0.5]B A[0.5,0.8]B A[>=0.8]B mintcut( 1:8, c( 2, 4, 7)) # [1] <NA> 2-3 2-3 4-6 4-6 4-6 7+ 7+ # Levels: 2-3 4-6 7+ mintcut( c( 1, 2, 4)) # auto bins, size defaulting to 1 # [1] 1 2 4+ # Levels: 1 < 2 < 3 < 4+ mintcut( c( 1, 2, 6), by=2) # auto bins of size 2 # [1] 1-2 1-2 5+ # Levels: 1-2 < 3-4 < 5+
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.