bin | R Documentation |
x
.bin
groups elements of x
into bins with either a
constant number of elements per bin, a constant bin width or according to
user-provided bin boundaries.
bin(
x,
binmode = c("equalN", "equalWidth", "breaks"),
nElements = round(length(x)/5),
nBins = NULL,
minAbsX = NULL,
breaks = NULL,
...
)
x |
A numerical vector with the values used for binning. |
binmode |
The algorithm to be used for binning. Possible values are: "equalN" (default), "equalWidth" or "breaks" (see Details). |
nElements |
The number of elements per bin (only for
|
nBins |
The number of bins (only for |
minAbsX |
The minimal absolute value in |
breaks |
Numerical vector with bin boundaries (only for
|
... |
further arguments to be passed to |
Elements are binned according to the values in x
depending on
binmode
:
Items are grouped into a variable
number of bins with nElements
elements each. If minAbsX
is
not NULL
, elements with x
-values in [-minAbsX,minAbsX]
will first be collected in a single bin before binning the remaining
elements. The boundaries of this single bin may be slightly adjusted in
order to respect the nElements
elements in the other bins.
Items are group into nBins
bins with a variable
number of elements each.
Items are grouped into bins using
cut(x, breaks, include.lowest = TRUE)
The return value from cut(x, ...)
, typically a factor of the
same length as x
. Binning mode, bin boundaries and the "neutral" bin
are available from attr(..., "binmode")
, attr(..., "breaks")
and attr(..., "bin0")
. For binmode = "breaks"
, the latter
will be NA
.
cut
which is used internally.
set.seed(1)
x <- rnorm(100)
summary(bin(x, "equalN", nElements=10))
summary(bin(x, "equalN", nElements=10, minAbsX=0.5))
summary(bin(x, "equalWidth", nBins=5))
summary(bin(x, "breaks", breaks=c(-10,-1,0,1,10)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.