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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 3 Jan 2000, BXC (Bendix Carstensen) wrote:> 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 think the date package is only intended to handle integers. This is partly because date.mdy is _not_ a function for converting numbers to dates, it is a function for converting dates to a printable form. If you look at as.date() the truncation is already done there, R> as.date(0) [1] 1Jan60 R> as.date(0.9) [1] 1Jan60 so a bona fide date object will always have an integer as the time since 1/1/1960. In that sense the workaround is to only use date.mdy on dates, not on numbers. I agree that it might be worth extending date to allow times in addition to dates (in which case it probably would have to have information on time zones as well). The tricky part would be parsing time information in character form, but there is probably GNU code for this. -thomas Thomas Lumley Assistant Professor, Biostatistics University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._