[Rd] as.factor: changed behaviour for Date class

From: Antonio, Fabio Di Narzo <antonio.fabio_at_gmail.com>
Date: Thu 27 Apr 2006 - 10:31:44 GMT


Dear all,
I have noticed a little change in the behaviour of as.factor from R-2.2.1 to R-2.3.0, and can't find it in the NEWS.

In R-2.3.0:
> times <- 1:5
> class(times) <- "Date"
> as.factor(times)

[1] 1 2 3 4 5
Levels: 1 2 3 4 5

In R-2.2.1:
> as.factor(times)

[1] 1970-01-02 1970-01-03 1970-01-04 1970-01-05 1970-01-06 Levels: 1970-01-02 1970-01-03 1970-01-04 1970-01-05 1970-01-06

Is this the intended behaviour?
Note that the change is reflected on other functions which seems to use as.factor internally, for example 'tapply'. Consider the following code:

times <- 1:5
class(times) <- "Date"

id <- rep(times, each=2)
vals <- rep(1:2,5)
tapply(vals, id, mean)

Under R-2.2.1 this gives:
1970-01-02 1970-01-03 1970-01-04 1970-01-05 1970-01-06

       1.5 1.5 1.5 1.5 1.5

But under R-2.3.0 the output is:
 1 2 3 4 5
1.5 1.5 1.5 1.5 1.5

Antonio, Fabio Di Narzo.

        [[alternative HTML version deleted]]



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Apr 27 20:35:12 2006

This archive was generated by hypermail 2.1.8 : Wed 03 May 2006 - 18:18:39 GMT