Which R time/date class and package to use?
Solution 1
(I am moving this from the comments to the answer portion of stackoverflow at the request of the original poster.)
There is an article in R News 4/1 ("R Help Desk", p. 29) that specifically compares Date
, POSIXct
and chron
. (The 1st two are in core of R and chron
is a package.)
timeDate
class (in the timeDate
package) is based on POSIXct
but has extra time zone/financial center support.
For regularly spaced series the the tis
package supports many notions of dates.
The mondate
package supports accounting dates.
The zoo
time series package supports just about any date/time class and also has yearmon
and yearqtr
for ts
compatibility.
The xts
time series package works on top of zoo
and handles the most common date/time classes by translating them to POSIXct
and back again.
There is also information in the Time Series CRAN Task View.
Solution 2
Use POSIXct and lubridate.
Solution 3
Rmetrics actually wrote a (free) ebook on the subject, "A Discussion of Time Series Objects for R in Finance", available at https://www.rmetrics.org/ebooks-tseries
Solution 4
Did you search old questions here? This has been discussed a lot -- use a search term such as
[r] zoo
to search for, say, zoo
within the R tag.
Of course this has also been discussed to death on the r-sig-finance list and other places.
FWIW my money is on zoo and xts. And to avoid S4 unless you really really need it.
VitoshKa
Updated on June 03, 2022Comments
-
VitoshKa almost 2 years
I have a limited time series exposure in R. So, I wonder which time/date class (and associated package) would be most appropriate to start with.
Among the plethora of packages available at CRAN task view, I so far favor the
timeDate
, which is a S4 oriented and has nice support for location dependent particularities such as holidays and daylight saving times.The community apparently favors the
zoo
package.chron
is also popular.
[edit: Here is a list of time/date implementations whichlubridate
package refers to: POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, its, ti, jul, timeSeries, fts. Alsolubridate
itself has handy time classesduration
,period
andinterval
.]Would really appreciate if somebody with experience with multiple packages would share his opinion on how the available time/date classes compare in terms of usability and extensibility.
Some points of interest (in random order):
- internationalization (holidays, timezones etc)
- readily available statistical modeling procedures
- readily available visualization tools
- ease of use
- compatibility with builtin date/time-series classes (POSIX,ts)
- extensibility (S4 is desirable)
- best to use with
lubridate
Thanks.