The change is not in as.factor: it is in sort (as called by factor) and it 
is documented in the NEWS file.

Why do you expect as.factor to convert a Date object to character and then 
to factor?  Please do the conversion explicitly.

On Thu, 27 Apr 2006, Antonio, Fabio Di Narzo wrote:

> 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
>
>

-- 
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
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

Reply via email to