binit | R Documentation |
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.
binit(samps,roundPrec=NULL)
samps |
A vector or array of data to be binned. |
roundPrec |
The number of digits to round |
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
.
A list containing two elements lengths: the number of items in each bin values: the data value associated with each bin
Carl Witthoft, carl@witthoft.com
rle
, hist
,
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.