[Rd] 'aggregate' should preserve level ordering of factors (PR#9666)

From: <prechelt_at_inf.fu-berlin.de>
Date: Tue, 08 May 2007 19:12:20 +0200 (CEST)

Full_Name: Lutz Prechelt
Version: 2.4.1
OS: Windows XP
Submission from: (NULL) (

aggregate (from package stats) should preserve the ordering of levels of factors it works on and also their 'ordered' attribute if present.
But it does not.

Here is an example:

ff = factor(c("a","b","a","b"),levels=c("b","a"),ordered=T) agg = aggregate(1:4, list(groups=ff), sum) print(levels(agg$groups)) # should be: "b" "a"
[1] "a" "b"

print(is.ordered(agg$groups)) # should be: TRUE

?aggregate ignores the issue completely: - the terms 'order' or 'level' do not occur in the   text at all
- the term 'factor' is mentioned only once:   "The elements of the list will be coerced to    factors (if they are not already factors)."

This issue made me write the following code used for preparing the data for a barchart:

  df.a = aggregate(df[,value.var],

                   list(grouping=dfgrouping, other=dfsubbar.var),

  if (is.factor(dfsubbar.var)) { # R 2.4: this should be done by 'aggregate'     df.a$other = factor(df.a$other,


R is great anyway. Thanks for your service building it!

  Lutz Prechelt

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 10 May 2007 - 09:05:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 May 2007 - 10:33:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.