cut
but for human use.mcut( x, breaks, pre.lab='', mid.lab='', post.lab='', digits=getOption( 'digits'))
mintcut( x, breaks, prefix='', all.levels=)
mintcut
x
exactly on the LH end of a bin will go into that bin, not the previous one. Should start with -Inf if necessary, but should not finish with Inf unless you want a bin for post.lab
instead.x
. To override "automatically", just set the "all.levels" attribute of breaks
to anything non-NULL; useful e.g. if you are repeatedly calling mintcut
with the same 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]"="" "[="">=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+
Run the code above in your browser using DataLab