# NOT RUN {
data <- dep_data
#calculate deciles for overcrowding
data$dec_overcrowd <- w_pcntile(data, total_pop, pcnt_overcrowding)
#average percent of overcrowding by decile
tapply(data$pcnt_overcrowding, data$dec_overcrowd, mean)
#percent of people in each decile
round(tapply(data$total_pop, data$dec_overcrowd, sum)/sum(data$total_pop)*100, 1)
#calculate quintiles from deciles
data$Q_overcrowd <- cut(data$dec_overcrowd, breaks = 5, labels = 1:5)
#calculate quintiles with w_pcntile
data$Q_overcrowd2 <- w_pcntile(data, total_pop, pcnt_overcrowding, p = 5)
#compare results - note small differences
table(data$Q_overcrowd, data$Q_overcrowd2)
# }
Run the code above in your browser using DataLab