Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the percentile function in CRAN -R

Tags:

r

I do not understand all the terminology inside R. I have only 100 level statistics, trying to learn more.

I am guessing R has a built-in percentile function named something I don't recognize or know how to search for.

I can write my own, but rather use the built in one for obvious reasons.

Here's the one I wrote:

percentile <- function(x) return((x - min(x)) / (max(x) - min(x))
like image 857
freewary Avatar asked Aug 23 '11 18:08

freewary


3 Answers

You can do this via

scale(x,center=min(x,na.rm=TRUE),scale=diff(range(x,na.rm=TRUE)))

but I'm not sure there is actually a built-in function that does the scaling you're asking for.

like image 64
Ben Bolker Avatar answered Sep 30 '22 20:09

Ben Bolker


If you are looking to find out specific percentiles from a data set, take a look at the quantile function: ?quantile. By multiplying by 100, you get percentiles.

If you are looking into converting numbers to their percentiles, take a look at rank, though you will need to determine how to address ties. You can simply rescale from rank to quantile by dividing by the length of the vector.

like image 45
Iterator Avatar answered Sep 30 '22 20:09

Iterator


The quantile function might be what you are looking for. If you have vector x and you want to know the 25th, 43rd, and 72nd percentiles you would execute this:

quantile(x, c(.25, .43, .72));

The semicolon is, of course, optional.

See http://www.r-tutor.com/elementary-statistics/numerical-measures/percentile

like image 35
adamleerich Avatar answered Sep 30 '22 19:09

adamleerich