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 which lubridate
package refers to: POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, its, ti, jul, timeSeries, fts. Also lubridate
itself has handy time classes duration
, period
and interval
.]
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):
lubridate
Thanks.
This chapter will focus on the lubridate package, which makes it easier to work with dates and times in R.
R has developed a special representation for dates and times. Dates are represented by the Date class and times are represented by the POSIXct or the POSIXlt class. Dates are stored internally as the number of days since 1970-01-01 while times are stored internally as the number of seconds since 1970-01-01.
The month and date separated by - . This default format used in R is the ISO 8601 standard for date/time. ISO 8601 is the internationally accepted way to represent dates and times and uses the 24 hour clock system. Let us create the release date using another function ISOdate() .
Note that the default date format is YYYY-MM-DD; therefore, if your string is of different format you must incorporate the format argument. There are multiple formats that dates can be in; for a complete list of formatting code options in R type ? strftime in your console.
(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.
Use POSIXct and lubridate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With