Re: [R] as.Date() clarification

From: Achim Zeileis <Achim.Zeileis_at_wu-wien.ac.at>
Date: Thu, 03 Jul 2008 11:37:21 +0200 (CEST)

On Thu, 3 Jul 2008, Ron Michael wrote:

> When I use the code as.Date(0) the I get : "1970-01-01". My question is
> why it is like that? help file on as.Date seems to give no light on
> that. Can anyone clarify me?

In R, "Date" objects are stored internally as the number of days since 1970-01-01 (typically the epoch on Unix systems):

## today
dd <- as.Date("2008-07-03")
dd

## number of days since 1970-01-01
dn <- as.numeric(dd)
dn

## In base R, you can reverse this if you specify the origin used as.Date(dn, origin = "1970-01-01")

## If you load package "zoo", this is made the default library("zoo")
as.Date(dn)

The idea of the zoo implementation is that you can switch back and forth between the "Date" and numeric representation. The implementation in base R, on the other hand, wants to be agnostic to the origin used and hence sets no default for that argument.

hth,
Z

>  
> Regards,
>
> Send instant messages to your online friends http://uk.messenger.yahoo.com
> [[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. Received on Thu 03 Jul 2008 - 09:49:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Jul 2008 - 10:31:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive