Learn R Programming

dvmisc (version 1.1.4)

cleancut: Convert Numeric to Factor with Convenient Interface

Description

So you can stop guess-and-checking with cut.

Usage

cleancut(x, breaks, labels = NULL)

Arguments

x

Numeric vector.

breaks

Character string, e.g. "[-Inf, 0), [0, 10], (10, Inf)".

labels

Character vector.

Value

Factor or integer vector.

Examples

Run this code
# NOT RUN {
x <- rnorm(100)
y <- cleancut(x, "(-Inf, -1), [-1, 1], (1, Inf)")
tapply(x, y, range)

y <- cleancut(x, "(-Inf, -1), [-1, 1], (1, Inf)", c("<-1", "-1 to 1", ">1"))
tapply(x, y, range)

# }

Run the code above in your browser using DataLab