?cut ?quantile (perhaps, to define the breaks)
Bert Gunter Genentech Nonclinical Biostatistics 650-467-7374 -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dan Dube Sent: Monday, April 06, 2009 12:45 PM To: r-help@r-project.org Subject: [R] "bucketing" observations is there a better way to bucket observations into more-or-less evenly sized buckets than this? it seems like this must be a common operation: dt = data.frame(points=rnorm(1000),bucket=NA) breaks = quantile(dt$points,seq(0:1,.1)) for (i in 2:length(breaks)) { if (i == 2) { ind = which(dt$points >= breaks[i-1] & dt$points <= breaks[i]) } else { ind = which(dt$points > breaks[i-1] & dt$points <= breaks[i]) } dt$bucket[ind] = i-1 } thanks! ______________________________________________ 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. ______________________________________________ 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.