interval {inum}R Documentation

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 class 'numeric'
interval(x, breaks = 50, ...)

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.

Value

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

See Also

cut

Examples


(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)]


[Package inum version 1.0-5 Index]