From ggrothendieck at myway.com  Mon Mar 22 23:43:11 2004
From: ggrothendieck at myway.com (Gabor Grothendieck)
Date: Mon Mar 22 23:43:17 2004
Subject: [Rd] as.Date.numeric
Message-ID: <20040322224311.290A53973@mprdmxin.myway.com>



In rereading my post, he as.Date(x)+as.Date(y) part of 
the equivalence should be removed.  The rest of it
is ok.


Date:   Mon, 22 Mar 2004 17:35:27 -0500 (EST) 
From:   Gabor Grothendieck <ggrothendieck@myway.com>
To:   <R-devel@stat.math.ethz.ch> 
Subject:   [Rd] as.Date.numeric 

 


Regarding the new R 1.9.0 Date class, it would be nice to have
as.Date.numeric . 

1. as.numeric(x) works for Date objects and it would be convenient 
to also have the inverse. 

2. It leads to some nice additive properties for integer x and y:
as.Date(x+y) = as.Date(x) + as.Date(y) 
= as.Date(x) + y = as.Date(y) + x

3. It gives a pleasing way to quickly get the origin:
as.Date(0)

4. The corresponding ability is already available in chron,
e.g. chron(0), and I have found that I did make use of it
in my work with chron.

5. Its particularly convenient in testing since you can quickly
generate a sequence of dates like this:
as.Date(1:100)

Its quite simple to implement:

as.Date.numeric <- function(x) structure( floor(x), class = "Date" )


[Rd] as.Date.numeric
Gabor Grothendieck