Description Usage Arguments Details Value Examples
View source: R/QuantileCutoffs.R
This function takes in a data.table, the column name of a measurement variable, the column name of a group variable, and a vector of quantiles in order to calculate quantile cutoffs for the measurement, by grouping.
1 | QuantileCutoffs(DT, values, grouping, quants, bMelt = TRUE, round.digit = 3)
|
DT |
A data.table that contains the data |
values |
A character string that names the column of observations to calculate quantiles over |
grouping |
A character string that names the column containing the groups to calculate quantiles for |
quants |
A vector of quantiles defining cuttoffs (e.g. what is the value
in |
bMelt |
A boolean indicating whether to output a long table (TRUE) or wide. Default behavior is to produce a long table, which is more suitable for plots |
round.digit |
An integer defining the decimal places to round the results to. Default behavior is 3 |
The flags melt and round control rounding of the resulting quantiles and whether to return a long table (suitable for plotting) or a wide table (better for presentation of the table)
A long or wide table showing quantile cutoffs for a given measurement by a group variable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ## - Example -
## By US state, what is the 30th and 70th percentile for number of
## jobs in that geographic area
library(data.table)
# Use data provided in this package
# - change column class to numeric
DT <- copy(fiberCountyDem)
DT[, JobsCount := as.numeric(JobsCount)]
values <- "JobsCount"
grouping <- "State"
quants <- c(.3, .7)
# Set bMelt to false to receive a wide table for display purposes
#
QuantileCutoffs(DT, values, grouping, quants, bMelt=FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.