I have columns of <customers> and <sales>. I want to calculate the <sales> values, corresponding to the relevant percentiles of <customers>. (e.g. sales volume corresponding to the upper 1% of customers, upper 10% of customers etc....
Hayk
I have columns of <customers> and <sales>. I want to calculate the <sales> values, corresponding to the relevant percentiles of <customers>. (e.g. sales volume corresponding to the upper 1% of customers, upper 10% of customers etc....
Hayk
I believe you are looking for the quantile()
function. If you have a vector of values called a
then you can compute the percentiles you want with:
quantile(a, c(.01,.05,.5,.95))
, if you want the first percentile, the first 5%, the mode and the 95%.
Something like that for the upper 25%?
sum(df$Sale[df$Sale>=quantile(df$Sale,probs=.75)])/sum(df$Sale)