[Rd] apply: new behaviour for factors in R-2.4.0

Christoph Buser buser at stat.math.ethz.ch
Mon Sep 25 13:57:57 CEST 2006

Dear R-core

There is a different output for the apply function due to the
change of unlist as mentioned in the R news.

Newly, applying as.factor() (or factor()) in

str(dat <- data.frame(x = 1:10, f1 = gl(2,5,labels = c("A", "B"))))
(d1 <- apply(dat,2,as.factor))

newly returns a character matrix while in R-2.3.1 the same
command resulted in an integer matrix that was consistent (up to
the ordering of the factor levels) with data.matrix().

The change is caused by the change of unlist() that, used for a
list of factors, newly returns a single factor instead of an
integer. I am happy with this change, but:

Is it desirable to change apply so that it does not return a
character matrix in the example above or include a warning for
such a case? 

Thank you very much for an answer.


Christoph Buser

Christoph Buser <buser at stat.math.ethz.ch>
Seminar fuer Statistik, LEO C13
ETH Zurich	8092 Zurich	 SWITZERLAND
phone: x-41-44-632-4673		fax: 632-1228

More information about the R-devel mailing list