make.bin.pctile.cols: Weighted Percentiles and Bin Numbers for Each Column, by...

View source: R/make.bin.pctile.cols.R

make.bin.pctile.colsR Documentation

Weighted Percentiles and Bin Numbers for Each Column, by zone, such as percentiles within each State

Description

This function just combines make.pctile.cols() and make.bin.cols(). Takes a data.frame of values and returns a data.frame (or matrix) of percentiles, showing the percentile of a value within all values in its column, as well as bin numbers, showing what bin each falls into, based on specified cutpoints defining bins.

** Work in progress/ not fully tested, e.g., need to test if all code below works with both as.df=TRUE and as.df=FALSE

Usage

make.bin.pctile.cols(
  raw.data.frame,
  weights = NULL,
  zone = NULL,
  as.df = TRUE,
  prefix.bin = "bin.",
  prefix.pctile = "pctile.",
  cutpoints = c((0:9)/10, 0.95, 1),
  labels = 1:11
)

Arguments

raw.data.frame

Data.frame of values

weights

Optional Numeric vector of weights to create weighted percentiles, such as population-weighted quantiles. Unweighted if not specified. Vector same length as number of rows in data.frame.

zone

NULL by default, but if a vector is provided, it defines zones to group by, so percentiles are within a given zone only.

as.df

Optional logical TRUE by default, in which case matrix results are converted to data.frame

prefix.bin

Optional character element, default is 'bin.', provides text to paste to beginning of input data.frame column names to use as bin output column names.

prefix.pctile

Optional character element, default is 'pctile.', provides text to paste to beginning of input data.frame column names to use as pctile output column names.

cutpoints

Default is 1:11. see make.bin.cols()

labels

Default is c(0.00, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 0.95, 1.00). see make.bin.cols()

Value

Returns a matrix or data.frame

See Also

make.bin.pctile.cols() to call functions below, converting columns of values to percentiles and then bins assign.pctiles() for one vector, assign (weighted) percentile (quantile) to each value within its zone (subset) assign.pctiles.alt2() as an alternative method, to replicate assign.pctiles, but not by zone get.pctile() to get (weighted) percentile of just 1+ values within given vector of values make.pctile.cols() for a data.frame, assign percentiles, return a same-sized df that is wtd.quantile of each value within its column make.pctile.cols.alt2() as an alternative method, to replicate make.pctile.cols assign.map.bins() for one vector (or data.frame) of values (e.g. percentiles), return same-sized df that is bin number (map color bin) using preset breaks. make.bin.cols() for a data.frame of values (e.g. percentiles), return same-sized df that is bin number (map color bin) using preset breaks. write.pctiles() to save file that is lookup table of percentiles for columns of a data.frame write.pctiles.by.zone() to save file that is lookup table of percentiles for columns of a data.frame, for each geographic zone (subset of rows) write.wtd.pctiles() to save file that is lookup table of weighted percentiles for columns of a data.frame write.wtd.pctiles.by.zone() to save file that is lookup table of weighted percentiles for columns of a data.frame, for each geographic zone (subset of rows) lookup.pctile() to look up current approx weighted percentiles in a lookup table that is already in global memory


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