prechelt at inf.fu-berlin.de
2007-May-08 17:12 UTC
[Rd] 'aggregate' should preserve level ordering of factors (PR#9666)
Full_Name: Lutz Prechelt
Version: 2.4.1
OS: Windows XP
Submission from: (NULL) (160.45.111.67)
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
[1] FALSE
-----
?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),
FUN=FUN)
if (is.factor(dfsubbar.var)) { # R 2.4: this should be done by
'aggregate'
df.a$other = factor(df.a$other,
levels=levels(dfsubbar.var),
ordered=is.ordered(dfsubbar.var))
}
Cumbersome.
R is great anyway. Thanks for your service building it!
Lutz Prechelt
Maybe Matching Threads
- (PR#9666) 'aggregate' should preserve level ordering of
- (PR#9589) 'union' does not handle factors while 'intersect'
- rbind.data.frame reacts on levels without factor (PR#9578)
- R CMD check: checking examples: how to (not) pause execution
- Trellis equivalent of par(ask=TRUE)?
