Learn R Programming

inum (version 1.0-5)

interval: Cut Numeric Vectors into Intervals

Description

interval divides x into intervals and, unlike cut, represents these as a numeric vector.

Usage

interval(x, ...)
# S3 method for numeric
interval(x, breaks = 50, ...)

Value

An object of class interval. A value of 0 encodes NA.

Arguments

x

A numeric vector.

breaks

Either a numeric vector of two or more unique cut points or a single number (greater than or equal to 2) giving the number of intervals into which x is to be cut by cut.

...

Additional arguments, currently ignored.

Details

This is just a wrapper around cut where the resulting intervals are stored as numeric values for simplified computation.

See Also

Examples

Run this code

(ix <- interval(x <- 0:100/100, breaks = 0:10/10))
(cx <- cut(x, breaks = 0:10/10))

attr(ix, "levels")
levels(ix)
levels(cx)

diag(table(ix, cx))

(ix <- interval(x <- c(NA, 0:100/100), breaks = 0:10/10))
ix[is.na(x)]
unclass(ix)[is.na(x)]

Run the code above in your browser using DataLab