[R] aggregate and ordered factors, feature?

From: David James <dj_at_research.bell-labs.com>
Date: Tue 20 Dec 2005 - 06:25:36 EST


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



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

Received on Tue Dec 20 06:40:49 2005

This archive was generated by hypermail 2.1.8 : Tue 20 Dec 2005 - 09:38:16 EST