简体   繁体   中英

How to calculate percentile.exe in R like we do in MS excel

How to calculate percentile.exc in r

I have some retail data where I need calculate the percentile (25th and 75th), mean median and the count based on Order_ID and Product ID. Checking upon the result with Excel calculation mean and median coming out correct but my percentile values are not matching.

25th Perc-13087.5, Average-24313.51667, Median-20167, 75th Perc-38916.25

     pivot_MRP <- Test %>% group_by(Product_Code) %>% 
                summarise(MRP_25 = quantile(MRP,0.25), 
                          MRP_Median = median(MRP),
                          MRP_1_Avg = mean(MRP), 
                          MRP_75 = quantile(MRP, 0.75),
                          MRP_count = n())

        pivot_Disc <- Test %>% group_by(Order_ID) %>% 
            summarise(MRP_25 = quantile(MRP,0.25), 
                      MRP_Median = median(MRP),
                      MRP_1_Avg = mean(MRP), 
                      MRP_75 = quantile(MRP, 0.75),
                      MRP_count = n())

Use quantile function.

data<-c(1,1,2,2,3,3) #Your data
quantile(data,c(0,0.25,0.5,0.75)) # Data and a vector of probabilities

Then you have.

  0%   25%   50%  75% 
  1.00 1.25 2.00 2.75 

Thanks for answer.

I figure out my self and found the answer.

                summarise(MRP_25 = quantile(MRP,0.25, type=6), 
                          MRP_Median = median(MRP),
                          MRP_1_Avg = mean(MRP), 
                          MRP_75 = quantile(MRP, 0.75, type=6),
                          MRP_count = n())'''

all we need add is 'type=6' in quantile

Thanks you all :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM