wesleysc352
wesleysc352

Reputation: 617

how to determine the percentile that a given value has in a sample in R

suppose I have a vector sample

x <-c (2,3,68,253,1,35,3,35,01,24,04,36,254,2,28,12,4,54,66,775,6,45,33,68,71)

I know that if I do the command:

quantile (x, 0.75) the R returns me the percentile P75 = 66.

but I would like to know, for example, in which percentile the value element 35 of my set x is located?

Would R answer such a question? is there an inverse of the quantile command?

Upvotes: 0

Views: 1205

Answers (1)

SteveM
SteveM

Reputation: 2301

To clarify the useful link reference of Taufi, you can assign a variable to the ecdf function and use that for single or vector calculations of the inverse value. E.g.

cdf <- ecdf(x)
cdf(35)
[1] 0.6
allx <- cdf(x)
allx
 [1] 0.16 0.24 0.84 0.92 0.08 0.60 0.24 0.60 0.08 0.44 0.32 0.64 0.96 0.16 0.48 0.40 0.32 0.72 0.76
[20] 1.00 0.36 0.68 0.52 0.84 0.88
cbind(x, allx)
        x allx
 [1,]   2 0.16
 [2,]   3 0.24
 [3,]  68 0.84
 [4,] 253 0.92
 [5,]   1 0.08
 [6,]  35 0.60
 [7,]   3 0.24
 [8,]  35 0.60
 [9,]   1 0.08
[10,]  24 0.44
[11,]   4 0.32
[12,]  36 0.64
[13,] 254 0.96
[14,]   2 0.16
[15,]  28 0.48
[16,]  12 0.40
[17,]   4 0.32
[18,]  54 0.72
[19,]  66 0.76
[20,] 775 1.00
[21,]   6 0.36
[22,]  45 0.68
[23,]  33 0.52
[24,]  68 0.84
[25,]  71 0.88

Upvotes: 3

Related Questions