Dan Bolser <[EMAIL PROTECTED]> wrote:
>
> Gabor Grothendieck wrote:
> > Do you mean you want g to be in the original order of x?
>
> No. What I mean is that I want to order x by any particular variable in
> my data.frame, then group over x such that each group has roughly the
> same sum.
>
> I get the feeling I have missed a very simple trick.

Maybe something like:

x <- data.frame(i=sample(1:10),j=1:10)
x2 <- x[order(x$i),]
x2$k <- cumsum(x2$j)
#
# 4 bins (;))
#
x2$bins <- cut(x2$k,quantile(x2$k), labels=F)
x2

David Duffy.

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to