mergebuckets: Merge adjacent buckets in a histogram to create a new...

Description Usage Arguments Details Author(s) See Also Examples

Description

Merge adjacent buckets in a histogram and return a new histogram.

Usage

1
  MergeBuckets(x, adj.buckets=NULL, breaks=NULL, FUN=sum)

Arguments

x

A histogram object (created by hist).

adj.buckets

The number of adjacent buckets to merge together.

breaks

If adj.buckets is equal to NULL, then this argument either specifies a vector giving the breakpoints between cells, or a single number giving the total number of cells in the new histogram. The vector of new buckets must have the same range as the original break list. If a single number is provided it must be less than length(x$breaks).

FUN

The user defined function that should be run to merge the counts of adjacent buckets in the histogram.

Details

Many data analysis pipelines write out histogram protocol buffers with thousands of buckets so as to be applicable in a wide range of contexts. This function provides a way to transform the histogram into one with fewer buckets.

Author(s)

Murray Stokely mstokely@google.com

See Also

histogramtools-package and hist.

Examples

1
2
3
4
5
hist.1 <- hist(c(1,2,3), breaks=c(0,1,2,3,4,5,6,7,8,9), plot=FALSE)
hist.2 <- MergeBuckets(hist.1, adj.buckets=2)

hist.1
hist.2

Example output

$breaks
 [1] 0 1 2 3 4 5 6 7 8 9

$counts
[1] 1 1 1 0 0 0 0 0 0

$density
[1] 0.3333333 0.3333333 0.3333333 0.0000000 0.0000000 0.0000000 0.0000000
[8] 0.0000000 0.0000000

$mids
[1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5

$xname
[1] "c(1, 2, 3)"

$equidist
[1] TRUE

attr(,"class")
[1] "histogram"
$breaks
[1] 0 2 4 6 8 9

$counts
[1] 2 1 0 0 0

$density
[1] 0.3333333 0.1666667 0.0000000 0.0000000 0.0000000

$mids
[1] 1.0 3.0 5.0 7.0 8.5

$xname
[1] "c(1, 2, 3)"

$equidist
[1] FALSE

attr(,"class")
[1] "histogram"

HistogramTools documentation built on May 2, 2019, 1:08 p.m.