Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best time date format for R [duplicate]

Tags:

datetime

format

r

Possible Duplicate:
Which R time/date class and package to use?

Hello,

I want to use a time date format for R, but there are so many packages that have their own format that I am a bit lost.

I was thinking of using the POSIXct/POSIXlt format. Is it the best (flexible enough for all use)

Thanks fRed

like image 731
RockScience Avatar asked Feb 02 '11 03:02

RockScience


People also ask

What format should time be in R?

The default format for times consists of the hour, minutes and seconds, separated by colons. Alternative formats can use the codes in Table . Often the first task when using the chron library is to break apart the date and times if they are stored together.

Is there a time data type in R?

In addition to the time data types R also has a date data type. The difference is that the date data type keeps track of numbers of days rather than seconds. You can cast a string into a date type using the as. Date function.

What is the default format for date in R?

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.

What is POSIXct format in R?

POSIXct stores date and time in seconds with the number of seconds beginning at 1 January 1970. Negative numbers are used to store dates prior to 1970. Thus, the POSIXct format stores each date and time a single value in units of seconds. Storing the data this way, optimizes use in data.


1 Answers

Date and POSIXct are both Base R types and highly recommended.

Packages such as zoo or xts use these types for indexing. Other packages like lubridate use them for date computation and parsing.

So your intuition was right: use Date and POSIXct.

like image 81
Dirk Eddelbuettel Avatar answered Sep 19 '22 22:09

Dirk Eddelbuettel