Re: [R] Partition into quantiles

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 05 Oct 2006 - 12:51:34 GMT

"Alberto Monteiro" <albmont@centroin.com.br> writes:

> Is there any function that divides a sample into N quantiles?
>
> For example, for N = 2, this would be the solution:
>
> x <- rnorm(100)
> m <- median(x)
> q <- ifelse(x <= median, 1, 2)

Have a look at

> N <- 2
> table(cut(x,quantile(x,seq(0,1,1/N)), include.lowest=TRUE))

[-2.78,0.205] (0.205,2.22]

           50 50

> table(cut(x,c(-Inf,quantile(x,(1:(N-1))/N),Inf)))

(-Inf,0.205] (0.205, Inf]

          50 50

-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Thu Oct 05 22:55:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 05 Oct 2006 - 13:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.