Try this:
df$group <- factor(df$group) levels(df$group)<- names(sort(tapply(df$weight, df$group, sum), decreasing=T)) On 28/11/2007, Serguei Kaniovski <[EMAIL PROTECTED]> wrote: > > > Dear All, > > Suppose I have the following dataframe: > > country;weight;group > bul;10;1 > cze;12;1 > grc;12;1 > hun;12;1 > prt;12;1 > rom14;1 > fra;29;2 > ita;29;2 > gbr;29;2 > aut;10;3 > bel;12;3 > > The "group" variable denotes the id-number of a group of countries. How > can > I re-label the groups in the descending order of their cumulative > "weight", > which wound be: > > country;weight;group > fra;29;1 > ita;29;1 > gbr;29;1 > bul;10;2 > cze;12;2 > grc;12;2 > hun;12;2 > prt;12;2 > rom14;2 > aut;10;3 > bel;12;3 > > The first group has the largest sum of weights, the second, with the > second > largest, and so on. > > Thanks for your help, > Serguei Kaniovski > > ________________________________________ > Austrian Institute of Economic Research (WIFO) > > P.O.Box 91 Tel.: +43-1-7982601-231 > 1103 Vienna, Austria Fax: +43-1-7989386 > > Mail: [EMAIL PROTECTED] > http://www.wifo.ac.at/Serguei.Kaniovski > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ 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.