On Fri, May 14, 2010 at 10:55 AM, Research <risk2...@ath.forthnet.gr> wrote: > Is there a function that returns the number of the "bin" (or quantile, or > percentile etc. etc.) that a value of a variable may belong to?
Something like this should work: dat <- round(runif(20, 0, 100)) hist.dat <- hist(dat, plot = FALSE) get.break.num <- function(x, breaks) { min((1:length(breaks))[x < breaks]) - 1 } # Then to use it: > get.break.num(6, hist.dat$breaks) [1] 1 > get.break.num(42, hist.dat$breaks) [1] 3 Sean ______________________________________________ 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.