[R-SIG-Finance] non-standard time-format conversion from data.frame to xts

Gabor Grothendieck ggrothendieck at gmail.com
Wed Dec 8 16:33:53 CET 2010


On Wed, Dec 8, 2010 at 10:01 AM, Jeff Ryan <jeff.a.ryan at gmail.com> wrote:
> I'd personally advise against using anything other than real
> POSIX-style time. Time alone can't exist without a date, certainly
> with respect to observable data.
>
> Do as Brian says and you'll have the most flexibility, but if you
> insist on just time chron can certainly be useful.  Note that chron
> uses fractional days to represent time, which is only an approximation
> of time - you will run into issues at certain times.
>
>> dput(as.chron(Sys.time()))
> structure(14951.6248495370, format = structure(c("m/d/y", "h:m:s"
> ), .Names = c("dates", "times")), origin = structure(c(1, 1,
> 1970), .Names = c("month", "day", "year")), class = c("chron",
> "dates", "times"))
>

You probably won't have any problems if you use times or POSIXct.

In particular since your resolution is one second that is more than
granular enough to represent it using floating point in chron and
times.  Its possible that errors could accumulate but not too likely.

With POSIXct you likely won't have a problem either but if you do then
the main problem is that you can introduce errors into your code due
to one routine assuming current time zone and another assuming GMT.
(xts itself is consistent but once you start using multiple packages
and even R itself there can be problems.) These errors are not that
frequent but when they occur they are extremely difficult to even know
that you have the error. The other problem is that there can be
unexpected results at day light saving time switch over.  With Date,
chron and times none of these problems occur since there are no time
zones and no day light savings times.  POSIXct is really best for
computer logs and applications like that where concepts like time
zones and day light savings time are important so you can synchronize
your logs with other time zones but is often not the most suitable for
statistical analysis where these only serve to introduce error.

With zoo and xts you do have a range of index classes to choose from,
just about any for zoo since they are defined by an API rather than
hard coded, and the half dozen or so most common for xts.

R News 4/1 discusses this more.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-SIG-Finance mailing list