[R] Partition into quantiles

Richard M. Heiberger rmh at temple.edu
Thu Oct 5 15:12:39 CEST 2006


cut.quantile <- function(x, N, use.ppoints=TRUE) {
  qq <- if (use.ppoints) c(0,ppoints(N-1),1)
  else seq(0, 1, 1/N)
  breaks <- quantile(x, qq)
  breaks[1] <- breaks[1] - 1 
  breaks[N+1] <- breaks[N+1]+1
  cut(x, breaks)
}

tmpT <- cut.quantile(rnorm(100), 10, TRUE)
table(tmpT)
tmpF <- cut.quantile(rnorm(100), 10, FALSE)
table(tmpF)



More information about the R-help mailing list