df <- data.frame(
region = as.character(rep(c("Region1","Region2","Region3","Region4"),
each=250)),
smallarea = as.character(paste0("Area",seq_along(1:1000))),
vals = as.numeric(sample(200, 1000, replace = TRUE)),
stringsAsFactors = FALSE)
# assign small areas to deciles across whole data frame
phe_quantile(df, vals)
# assign small areas to deciles within regions by pre-grouping the data frame
library(dplyr)
df_grp <- df %>% group_by(region)
phe_quantile(df_grp, vals)
# assign small areas to quintiles, where highest value = highest quantile
phe_quantile(df, vals, nquantiles = 5L, invert=FALSE)
Run the code above in your browser using DataLab