Description Usage Arguments Details Value Errors See Also Examples
View source: R/dataRangeReductionUtils.R
Basically this is a convenience wrapper around cut
.
1 |
data |
A vector of numeric data to bin. Where values are |
binEnds |
The n+1 ends of the n bins into which the data is sorted. One
bin might be |
binLabels |
The vector of names corresponding to the labels of the bin a value belongs in. |
Maps labels to a vector of numeric data based on a vector of bin ends. Each
label corresponds to one of n bins defined by n+1 bin boundaries (including
start and end boundaries, probably -Inf
and Inf
). It is an
error if the number of bins and the number of labels differ. Returns a vector
of the same length as data, but with each value replaced by the binLabel for
the bin it was sorted into. E.g if the bin labels are categories like "low",
"medium" and "high", this converts data to categories. Values equal to bin
boundaries are put in the lower bin, with the lowest bin boundary also
included in the lowest bin. Note, bin ends are always sorted from lowest to
highest. If you want the labels in the other order, just reverse the labels
vector.
The vector of bin labels corresponding to the bins the data was sorted into.
'breaks' are not unique
It is an error if any bin end is repeated.
lengths of 'breaks' and 'labels' differ
It is an error if the number of labels differs from the number of bins, or equivalently is not one less than the number of bin ends.
1 2 3 4 5 6 7 8 9 | ends = c(Inf,-Inf,1,-1) # Sorted to c(-Inf, -1, 1, Inf)
labels = c('-', '0', '+' )
mapLabels( c(-Inf,-5,-1,-0.5,0,0.5,1,5,Inf), ends, labels)
#=> [1] "-", "-", "-", "0", "0", "0", "0", "+", "+"
ends = c(-10, 0, 10)
labels = c('-', '+')
mapLabels( c(-20, -10, -5, 0, NA, 5.2, 10, Inf), ends, labels)
#=> [1] NA "-" "-" "-" NA "+" "+" NA
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.