Learn R Programming

cgwtools (version 4.1)

binit: Create histogram bins for each unique value in a sample.

Description

This is a Q&D way to create Pareto / histogram bins of a dataset when you want a separate bin for each value and don't want to deal with the 'breaks' or equivalent arguments in hist or other histogram functions in R packages.

Usage

binit(samps,roundPrec=NULL)

Value

A list containing two elements lengths: the number of items in each bin values: the data value associated with each bin

Arguments

samps

A vector or array of data to be binned.

roundPrec

The number of digits to round samps to. Highly recommended when the data are floats

Author

Carl Witthoft, carl@witthoft.com

Details

binit sorts the input data and feeds the result to rle. This effectively produces histogram-like results. If you want a strict Pareto order (most common first), just sort the list elements lengths and values by the magnitudes in lengths.

See Also

rle , hist,

Examples

Run this code
x <- sample(1:100, 1000, rep=TRUE)
xbin <- binit(x)
plot(xbin$values,xbin$lengths, type = 'h')
# without rounding, will just be grass
x <- rnorm(1000)
 xbin <- binit(x,2)
plot(xbin$values,xbin$lengths, type = 'h')

Run the code above in your browser using DataLab