interval: Cut Numeric Vectors into Intervals

Description Usage Arguments Details Value See Also Examples

View source: R/interval.R

Description

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

Usage

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
(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)]

inum documentation built on Dec. 12, 2017, 3:01 p.m.