assign.map.bins: Assign Each Row (Place) to a Bin Based on Cutpoints

View source: R/assign.map.bins.R

assign.map.binsR Documentation

Assign Each Row (Place) to a Bin Based on Cutpoints

Description

Takes a vector (not matrix or df) of values and returns a vector of bin numbers. For creating color-coded maps (choropleths), assign each place (e.g., each row of a single column) to a bin. Each bin represents one map color, and is defined by threshold values.

Usage

assign.map.bins(
  pctiles.vector,
  cutpoints = c((0:9)/10, 0.95, 1),
  labels = 1:11
)

Arguments

pctiles.vector

Vector of percentiles as decimal fractions, 0 to 1, one per place.

cutpoints

Optional vector of cutpoints defining edges of bins. Default is every 0.10 from 0 to 1.00, as well as 0.95

labels

vector of bin numbers, optional (default is 1 through 11, and NA values are put in bin 0).

Details

The default bins 0-11 are defined as follows:
bin 0: PCTILE=NA
...
bin 9: 0.80<=PCTILE<0.90
bin 10: 0.90<=PCTILE<0.95
bin 11: 0.95<=PCTILE<=1.00

Value

Returns a vector bin numbers.

See Also

make.bin.pctile.cols() and assign.pctiles()

Examples

junk<-c(0,0.799,0.8, 0.8000001, 0.8999999,0.95,0.95001,1)
data.frame(pctile=junk, bin=assign.map.bins(junk))
# How it puts these in bins by default:
#      pctile bin   notes
#1  0.0000000   1
#2  0.7990000   8
#
#3  0.8000000   9 (0.80<=PCTILE<0.90 )
#4  0.8000001   9 (0.80<=PCTILE<0.90 )
#5  0.8999999   9 (0.80<=PCTILE<0.90 )
#
#6  0.9000000  10 (0.90<=PCTILE<0.95 )
#7  0.9001000  10 (0.90<=PCTILE<0.95 )
#8  0.9499990  10 (0.90<=PCTILE<0.95 )
#
#9  0.9500000  11 (0.95<=PCTILE<=1.00 ) I.E. THIS INCLUDES 100th percentile
#10 0.9500100  11 (0.95<=PCTILE<=1.00 ) I.E. THIS INCLUDES 100th percentile
#11 1.0000000  11 (0.95<=PCTILE<=1.00 ) I.E. THIS INCLUDES 100th percentile

ejanalysis/ejanalysis documentation built on April 2, 2024, 10:12 a.m.