[R] aggregate and ordered factors, feature?

David James dj at research.bell-labs.com
Mon Dec 19 20:25:36 CET 2005


Hi,

aggregate() does not preserve the order of levels for
ordered factors, e.g.,

   levs <- c("Low", "Med", "Hi")
   d <- data.frame(x = 1:30, fac = ordered(rep(levs, 10), levels = levs))
   out <- aggregate(d[,"x"], by = list(fac=d$f), FUN = mean)

   cat("Original ordered levels:", levels(d$fac), "\n")
   cat("Levels in aggregated output:", levels(out$fac), "\n")

Perhaps this is unintended?  If intended, a note in its documentation 
could be helpful to alert users.

> ô version
         _
platform i686-pc-linux-gnu
arch     i686
os       linux-gnu
system   i686, linux-gnu
status   beta
major    2
minor    2.1
year     2005
month    12
day      18
svn rev  36792
language R

--
David




More information about the R-help mailing list