TobiSonne
TobiSonne

Reputation: 1107

Get quantile for each value

Is there an implemented (!) function in R which gives you the empirical quantile for each value? I couldn't find any ...

Let's say we have x

x = c(1,3,4,2)

I want to have the quantile of each element.

[1] 0.25, 0.75, 1, 0.5 

Upvotes: 2

Views: 2090

Answers (1)

johnckane
johnckane

Reputation: 645

You can use the ecdf() function:

ecdf(x)(x)
[1] 0.25 0.75 1.00 0.50

ecdf(x) creates a function, and you pass the elements of x to that function. The syntax admittedly looks strange

Upvotes: 7

Related Questions