简体   繁体   中英

How to calculate percentile in R?

In R help help(quantile) ,you can see

Type 7 m = 1-p.  p[k] = (k - 1) / (n - 1).  In this case, p[k] =mode[F(x[k])]. 
This is used by S.

now ,i have a example:

w<-c(75,64,47.4,66.9,62.2,62.2,58.7,63.5,66.6,64,57,69,56.9,50,72.0)  
sort(w)  
[1] 47.4 50.0 56.9 57.0 58.7 62.2 62.2 63.5 64.0 64.0 66.6 66.9 69.0 72.0 75.0  
quantile(w)  
   0%   25%   50%   75%  100%   
47.40 57.85 63.50 66.75 75.00  

How can you use the type 7 formula to get the result?

I'm having some trouble deciding if the answer is just:

> quantile(w, type=7)
   0%   25%   50%   75%  100% 
47.40 57.85 63.50 66.75 75.00 

My problem is that the default for quantile is type=7 and you already have that result. If you look at the code for quantile.default there is a section for type=7:

        index <- 1 + (n - 1) * probs
        lo <- floor(index)
        hi <- ceiling(index)
        x <- sort(x, partial = unique(c(lo, hi)))
        qs <- x[lo]
        i <- which(index > lo)
        h <- (index - lo)[i]
        qs[i] <- (1 - h) * qs[i] + h * x[hi[i]]

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