[Rd] as.Date.numeric

Gabor Grothendieck ggrothendieck at myway.com
Mon Mar 22 23:35:27 CET 2004



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



More information about the R-devel mailing list