[R] Rounding in date.mdy from library(date)

BXC (Bendix Carstensen) BXC at novo.dk
Mon Jan 3 11:05:16 CET 2000


> The date library contains a function date.mdy that converts a number
> D to the date (month,date,year as a list) at D days after 1 Jan 1960.
> This a convention that fits in with SASs.
> 
> The logic would be that the result was the date at D days after
> 1 Jan 1960 00:00:00 (which is a POINT in time as opposed to a date which 
> is an interval), so that any D with 2<=D<3 was rounded to 3 Jan 1960
> and so on. This is because at any time D days (i.e. D*24h) after 
> 1.1.1960:00:00 with 2<=D<3 we would call the date "3 Jan 1960".
> 
> I cannot decipher the algorithm from the code in the function, but the 
> rounding procedure certainly produces some funny results, as the following
> 
> piece of clumsy code demonstrates:
> 
> dex <- function(jul.dat,N=1000)
>        {
>        # Functions that finds the fraction to add to a number
>        # to make the date.mdy round upwards (should be 1) 
>        (0:N)[(abs(diff(date.mdy(jul.dat+0:N/N)$day))>0.5)]/N
>        }
> jd <- 0:200 * 300
> rf <- 0
> for (i in 1:201) rf[i] <- dex(jd[i])
> plot(jd,rf,pch=".")
> 
> The obvous workaround would be to mask date.mdy by:
> 
> real.date.mdy <- function(jd) date.mdy(floor(jd))
> 
> Is this an error or is there a feature somewhere that I am missing?
> 
> Bendix Carstensen
> 
>                       \\\|///
>                      \\ - - /
>                      (  @ @ )  
> +------------------o00o-(_)-o00o-------------------------+
> | Bendix Carstensen                 tel: +45 44 43 87 38 |
> | Senior Statistician               SDC: +45 44 43 90 42 |
> | Steno Diabetes Center             fax: +45 44 43 73 13 |
> | Niels Steensens Vej 2              e-mail: bxc at novo.dk |
> | DK - 2820 Gentofte       http://www.biostat.ku.dk/~bxc |
> | Denmark                   Ooooo                        |
> +------------------ooooO----(   )------------------------+
>                    (   )     ) /
>                     \ (     (_/
>                      \_)
> 
> 
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list