Learn R Programming

playwith (version 0.9-32)

cutEq: Cut into equal-sized groups.

Description

Discretize using equally spaced quantiles for the breaks.

Usage

cutEq(x, n, type = 2, dig.lab = 4, ...)

reorderByFreq(x)

Arguments

x
for cutEq, a numeric vector. for reorderByFreq, a factor variable.
n
number of levels (groups) to cut into.
type
type of quantile, see quantile.
dig.lab
digits to use in formatting labels.
...
ignored.

Value

  • cutEq returns an ordered factor. reorderByFreq returns a factor with the same values as its input, but with levels reordered.

Details

cutEq is similar to cut but divides into roughly equally-sized groups, rather than dividing into bins of equal width. reorderByFreq orders levels of a factor by their frequency. It is basically reorder(x, x, length), but reversed.

See Also

cut, cut2 in Hmisc package, reorder

Examples

Run this code
summary(cut(rnorm(100), 4, dig=2))
summary(cutEq(rnorm(100), 4, dig=2))

foo <- factor(c("c","b","b","a"))
levels(foo)
# "a" "b" "c"
levels(reorderByFreq(foo))
# "b" "a" "c"

Run the code above in your browser using DataLab