[R] quantile
jim holtman
jholtman at gmail.com
Mon Sep 29 23:17:02 CEST 2008
?quantile
?cut
> x <- runif(10)
> y <- quantile(x, prob=seq(0,1,.25))
> y
0% 25% 50% 75% 100%
0.06178627 0.29216247 0.60098370 0.83899171 0.94467527
> cut(x, breaks=y, include.lowest=TRUE)
[1] [0.0618,0.292] (0.292,0.601] (0.292,0.601] (0.839,0.945]
[0.0618,0.292] (0.839,0.945]
[7] (0.839,0.945] (0.601,0.839] (0.601,0.839] [0.0618,0.292]
Levels: [0.0618,0.292] (0.292,0.601] (0.601,0.839] (0.839,0.945]
> cut(x, breaks=y, include.lowest=TRUE, labels=FALSE)
[1] 1 2 2 4 1 4 4 3 3 1
> x
[1] 0.26550866 0.37212390 0.57285336 0.90820779 0.20168193 0.89838968
0.94467527 0.66079779 0.62911404
[10] 0.06178627
>
On Mon, Sep 29, 2008 at 4:09 PM, liujb <liujulia7 at yahoo.com> wrote:
>
> Hello,
>
> I need to assign a number to each x[i], i=1:100, based on the value of x[i]
> and where they are in the distribution of x[i]. For example 1 for x[4] means
> x[4] is below 25%. I can obtain the quantile using quantile command, and
> just loop through the 1:100 and assign the correct number. But I was just
> wondering whether there are a more efficient way.
>
> Thank you,
> sincerely,
> Julia
> --
> View this message in context: http://www.nabble.com/quantile-tp19730778p19730778.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list