[R] Date format in plot

David Winsemius dwinsemius at comcast.net
Tue Sep 1 21:30:44 CEST 2009


On Sep 1, 2009, at 3:13 PM, Erik Iverson wrote:

> We will need a reproducible example!  Please give us R commands that  
> display the behavior you're observing:
>
> For example,
>
> I am having trouble understanding the as.Date function.  When I  
> input 39939, I would like to get "06.05.2009", but when I try it, I  
> get
>
>> as.Date(39939)
> Error in as.Date.numeric(39939) : 'origin' must be supplied
>
> I looked up what origin Excel uses for its' dates, and it seems like  
> it might be January 1, 1900, so I tried
>
> as.Date(39939, origin = "1900-01-01")
> [1] "2009-05-08"
>
> Then we will much better be able to help you, because we will be  
> able to paste your commands into R and see the results and make  
> changes.
>
> But this still seems to be off by two days.  So did you really mean  
> "06.05", or "08.05"?

One of the two day discrepancy is because the real date on which Excel  
dates are based is NOT 1900-01-01:

http://support.microsoft.com/default.aspx?scid=kb;en-us;214058

They claim that fixing this would be too difficult and doesn't caus  
very many difficulties anyway, but apparently refuse to publish the  
correct starting date in their documents. Where the other missing day  
went I cannot say. It may have something to do with different  
definitions for where a date is supposed to start.

>
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org 
> ] On Behalf Of swertie
> Sent: Tuesday, September 01, 2009 12:59 PM
> To: r-help at r-project.org
> Subject: [R] Date format in plot
>
>
> Hello, I plot the abundance of a species in relation to the date. To  
> have the
> date as a continous variable I put it in the format "standard" in  
> excel
> (f.ex. 39939 means 06.05.2009). R uses 39939 on the x axis, but I  
> would like
> to have "06.05". I tried to use as.Date as suggested in some  
> discussion but
> I don't manage to use it, the returned date is not correct. Do you  
> have any
> clue? thank you
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list