[R] Partition into quantiles
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Thu Oct 5 14:51:34 CEST 2006
"Alberto Monteiro" <albmont at 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 at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list