interval_bin: Bin data into intervals (1d).

Description Usage Arguments Details Value See Also Examples

Description

Bin data into intervals (1d).

Usage

1
2
interval_bin(x, weight, breaks=interval_breaks(),
    na.rm=FALSE, open="right")

Arguments

x

a numeric vector of positions

weight

NULL or a numeric vector providing weights for each observation

breaks

a vector of break points that should enclose all x values

na.rm

If TRUE missing values will be silently removed, otherwise they will be removed with a warning.

open

are intervals open on the "left" or the "right". This can make a big difference when your data is more discrete.

Details

To deal with floating point rounding issues, bin positions are rounded slighty up or slightly down (depending on whether open is right or left). This technique is adapted from hist.

Value

A data frame with three columns:

left

the left end of the interval

right

the right end of the interval

count

the number of observations in that interval

See Also

ash_1d

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- interval_bin(runif(100))
# Simple plot methoded included in package
plot(x)

# Selecting breaks:
interval_bin(runif(100), breaks = interval_breaks(bins = 10))
interval_bin(runif(100), breaks = interval_breaks(binwidth = 0.1))
interval_bin(runif(100), breaks = seq(0, 1, by = 0.2))
interval_bin(runif(100), breaks = scott_breaks())
interval_bin(runif(100), breaks = dhist_breaks())

hadley/densityvis documentation built on May 17, 2019, 9:56 a.m.