[R] chron and mysql

Kurt Hornik Kurt.Hornik at ci.tuwien.ac.at
Wed Feb 23 12:46:53 CET 2000


>>>>> Joel Allen writes:

> R 0.90.1
> chron 2.2-2
> MySQL 3.22.30

> Attempts to create a chron object fail when using date and time data
> from a mysql database.   It appears that chron does not like 4 digit
> years.  Is this the problem?

Yes, and no.  The current design of chron is meant to use `y' as a
2-digit only year qualifier.  Version 2.2-2 has added code which will
make this work across 2000 as well.

To ready that in, you can easily write your own code.  E.g.,

infmt <- function(str) {
    x <- strsplit(str, "-")
    i <- seq(from = 0, length = length(x), by = 3)
    x <- as.integer(unlist(x))
    julian(y = x[i+1], m = x[i+2], d = x[i+3])
}

R> chron(infmt(c("2000-03-12", "1999-12-22")))
[1] 03/12/00 12/22/99

-k

> my data look like:

>> c.time[1:10,]
>          Date     Time
> 1  2000-02-14 10:15:02
> 2  2000-02-14 10:17:03
> 3  2000-02-14 10:18:03
> 4  2000-02-14 10:19:03
> 5  2000-02-14 10:20:04
> 6  2000-02-14 10:21:04
> 7  2000-02-14 10:22:04
> 8  2000-02-14 10:23:05
> 9  2000-02-14 10:24:05
> 10 2000-02-14 10:26:06

> the chron command looks like:

>> 
> time.stamp<-chron(as.character(c.time[,"Date"]),c.time[,"Time"],format=c("y/m/d","h:m:s"))

> Error in convert.dates(dates., format = format[[1]], origin = origin.) :
> format y/m/d may be incorrect
> In addition: Warning messages:
> 1: 1796 entries set to NA due to wrong number of fields in:
> unpaste(dates., sep = fmt$sep, fnames = fmt$periods, nfields = 3)
> 2: NAs introduced by coercion
> 3: NAs introduced by coercion
> 4: NAs introduced by coercion

> Thanks,

> Joel Allen
> Institute of Applied Sciences
> University of North Texas

> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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