[R] Vectors of years, months, and days to dates?

Richard A. O'Keefe ok at cs.otago.ac.nz
Tue Jun 8 04:57:23 CEST 2004


Rolf Turner <rolf at math.unb.ca> attacked:
		Have you ***any*** evidence that R's procedure degrades
		performance, under any circumstances?  (Apparently not.) In
		that case why are you going on and on about it?
	
I did the following:

    library(chron)
    ymd.to.POSIXlt <-
        function (y, m, d) as.POSIXlt(chron(julian(y=y, x=m, d=d)))
    n <- 100000
    y <- sample(1970:2004, n, replace=TRUE)
    m <- sample(1:12,      n, replace=TRUE)
    d <- sample(1:28,      n, replace=TRUE)
    system.time(ymd.to.POSIXlt(y, m, d))
    [1]  8.78  0.10 31.76  0.00  0.00
    system.time(as.POSIXlt(paste(y,m,d, sep="-")))
    [1] 14.64  0.13 53.30  0.00  0.00

This was on a 500MHz SunBlade100, a slow machine by today's standards,
using R 1.9.0.  There is all the evidence one could reasonably ask for
that going through paste() instead of providing y, m, d as numeric
vectors *does* degrade performance under at least some circumstances.

The cost is less than a factor of 2, but not negligible either.

		The standard response to this kind of request is ``R is a
		cooperative endeavour.  Feel free to contribute.''
	
Well, ymd.to.POSIXlt is my contribution.

	> Is there no one supporting my idea?
	
		Apparently not.
	
Wrong:  the idea *is* already supported (all except for one trivial
line of code) by the chron package.




More information about the R-help mailing list