ראובן אברמוביץ
2011-Aug-02 14:14 UTC
[R] how to get the percentile of a number in a vector
I'm familiar with the quantile() command, but what if I have a specific number that I want to know its location in a vector? I know that in known distributions, (for example the normal distribution), there is pnorm and qnorm, but how can I do it with unknown vector? thanks in advance _________________________________________________________________ Walla! Mail - [1]Get your free unlimited mail today References 1. http://www.walla.co.il/
David Winsemius
2011-Aug-02 16:00 UTC
[R] how to get the percentile of a number in a vector
On Aug 2, 2011, at 10:14 AM, ????? ???????? wrote:> > I'm familiar with the quantile() command, but what if I have a > specific > number that I want to know its location in a vector? I know that > in known > distributions, (for example the normal distribution), there is > pnorm and > qnorm, but how can I do it with unknown vector??ecdf -- David Winsemius, MD West Hartford, CT
R. Michael Weylandt <michael.weylandt@gmail.com>
2011-Aug-02 16:07 UTC
[R] how to get the percentile of a number in a vector
Would this work for you? if you want to know where the i-th element falls percentage-wise in the distribution of a vector: sum(x <= x[i])/length(x) This could be turned into a function: pEmpirical <- function(i,x) { if (length(i) > 1) return(apply(as.matrix(i), 1, pEmpirical,x)) r = sum(x <= x[i])/length(x) return(r) } Michael Weylandt 2011/8/2 ראובן אברמוביץ <gantkant@walla.com>> > I'm familiar with the quantile() command, but what if I have a specific > number that I want to know its location in a vector? I know that in known > distributions, (for example the normal distribution), there is pnorm and > qnorm, but how can I do it with unknown vector? > > > thanks in advance > _________________________________________________________________ > > Walla! Mail - [1]Get your free unlimited mail today > > References > > 1. http://www.walla.co.il/ > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >[[alternative HTML version deleted]]
Does this help? x <- c(3, 8, 5, 2, 9, 33, 21) # the 43rd percentile quantile(x, 0.43) # the proportion of the distribution that is less than 7 mean(x<7) Jean `·.,, ><(((?> `·.,, ><(((?> `·.,, ><(((?> Jean V. Adams Statistician U.S. Geological Survey Great Lakes Science Center 223 East Steinfest Road Antigo, WI 54409 USA From: øàåáï àáøîåáéõ <gantkant@walla.com> To: <r-help@r-project.org> Date: 08/02/2011 10:51 AM Subject: [R] how to get the percentile of a number in a vector Sent by: r-help-bounces@r-project.org I'm familiar with the quantile() command, but what if I have a specific number that I want to know its location in a vector? I know that in known distributions, (for example the normal distribution), there is pnorm and qnorm, but how can I do it with unknown vector? thanks in advance _________________________________________________________________ Walla! Mail - [1]Get your free unlimited mail today References 1. http://www.walla.co.il/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]