mapLabels: Maps values into labeled bins

Description Usage Arguments Details Value Errors See Also Examples

Description

Basically this is a convenience wrapper around cut.

Usage

1
mapLabels(data, binEnds, binLabels)

Arguments

data

A vector of numeric data to bin. Where values are NA, above the highest bin end, or below the lowest they convert to NA in the returned label vector.

binEnds

The n+1 ends of the n bins into which the data is sorted. One bin might be c(-Inf, Inf). Two bins equally weighted would be c(-Inf, median(data), Inf). This vector will be sorted before assigning labels, so reverse the label order instead of providing bins as high to low. Data exactly matching bin ends will be in the lower bin, with the lowest bin end also part of the lowest bin. It is an error if any bin end is repeated.

binLabels

The vector of names corresponding to the labels of the bin a value belongs in.

Details

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.

Value

The vector of bin labels corresponding to the bins the data was sorted into.

Errors

'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.

See Also

cut

Examples

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

jefferys/fusionExpressionPlot documentation built on May 19, 2019, 3:59 a.m.