View source: R/calculate_percentiles.R
| calculate_stratified_percentiles | R Documentation |
Calculate percentiles for values in a data.frame while stratifying for other characteritics in same df
calculate_stratified_percentiles(data, value_col, stratify_by, use.na = FALSE)
data |
A data frame |
value_col |
character name of column containing values |
stratify_by |
list or vector. Use a named list to specify column name as key and a value of type vector indicating accepted levels of the property stratified by to be included. If an unnamed list or vector is passed, all levels of indicated columns will be used |
use.na |
A logical indicating whether NA values should be used. If TRUE, NA values and non-included value levels will be grouped like a separate value level |
A vector of numerics with percentile values of length of nrow(data)
J. Peter Marquardt
data <- data.frame('values' = 100:1, 'group' = rep(c('A', 'B', NA, 'D'), 25))
calculate_stratified_percentiles(data, 'values', list(group = c('A', 'B', 'D')))
calculate_stratified_percentiles(data, 'values', c('group'), use.na = TRUE)
calculate_stratified_percentiles(data, 'values', list(group = c('A', 'C')), use.na=TRUE)
# The following example will result in NA values caused by NAs in 'group'.
# Therefore, it will return the percentile vector, but issue a warning.
calculate_stratified_percentiles(data, 'values', 'group')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.