# NOT RUN {
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 within regions - method 1: assign grouping set within function
phe_quantile(df, vals, region)
# assign small area to deciles within regions - method 2: pre-group input dataframe
library(dplyr)
df_grp <- df %>% group_by(region)
phe_quantile(df_grp, vals)
# assign smallareas to decile across whole data frame (ignoring region)
phe_quantile(df, vals)
# assign smallareas to quintiles within regions, where high val = lowest quantile
phe_quantile(df, vals, region, invert=FALSE)
# }
Run the code above in your browser using DataCamp Workspace