-----Original Message-----
From: Dimitris Rizopoulos [mailto:d.rizopoulos at erasmusmc.nl]
Sent: Monday, April 06, 2009 4:01 PM
To: Dan Dube
Cc: r-help at r-project.org
Subject: Re: [R] "bucketing" observations
try this:
dat <- data.frame(vals = rnorm(1000))
breaks <- quantile(dat$vals, seq(0, 1, .1)) dat$bucket <-
cut(dat$vals, breaks, labels = FALSE, include.lowest = TRUE)
I hope it helps.
Best,
Dimitris
Dan Dube wrote:
is there a better way to bucket observations into
sized buckets than this? it seems like this must be a
dt = data.frame(points=rnorm(1000),bucket=NA)
breaks = quantile(dt$points,seq(0:1,.1)) for (i in
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!