[R] Which date format to choose?

R. Michael Weylandt michael.weylandt at gmail.com
Tue Jan 17 18:35:15 CET 2012


"R offers a bewildering array of options when it comes to representing
dates and times"

Yes & no: read www.r-project.org/doc/Rnews/Rnews_2004-1.pdf (the help
desk section)

Brief summary: 3 major ways to deal with dates/times in R:

i ) the Date class from the base distribution -- no time support, but very easy
ii) the chron (package) -- no support for time zones but can do times of day
iii) POSIXt (in two forms) -- the most general -- handles time zones
and daylights savings, but has a few quirks

General rule: use the simplest one you can but no simpler.

Where things get more complicated is in the time series object itself:

zoo is very general (doesn't actually even require a time object for
the index) and its derivative xts is my personal workhorse. I can only
speak from a quant-finance perspective but, in that domain, the
decision comes down to xts from quantmod (actually standalone but
tightly integrated) vs timeDate from Rmetrics. They are both very good
-- one is S3 and one is S4 so they have different virtues; I'm not an
S4 guy myself so that drives me to the xts choice.  xts is pretty much
impossible to beat for speed though if that's a factor (it uses POSIXt
objects for the index and all sorts of great C routines) If speed
isn't a concern, I'd suggest you see whichever one has better support
for what you are trying to do and to make your decision based on that.
Rmetrics is an extensive platform for analysis and econometrics, but
the quantmod/quantstrat toolkit is more geared towards a trader (at
least, in my impression)

Others will hopefully chime in but it's going to be alot easier if you
can say a little more about your problem domain and what sort of
analysis you want to run. It also might behoove you to look at the
timeSeries CRAN task view.

Hope this helps,

Michael

On Tue, Jan 17, 2012 at 12:14 PM, Jake Beaulieu
<Beaulieu.Jake at epamail.epa.gov> wrote:
> R offers a bewildering array of options when it comes to representing
> dates and times (e.g, as.Date, chron, strptime, zoo, etc).  Can anybody
> recommend a document that compares the relative merit of each method?  I'm
> not looking for help with any one method, but rather a guide that
> describes which method is best for a particular data analysis/plotting
> goal.
>
> Thanks,
> Jake
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list