[R] Date issues

David Winsemius dwinsemius at comcast.net
Sat Sep 18 18:54:18 CEST 2010


On Sep 18, 2010, at 11:36 AM, David Winsemius wrote:

>
> On Sep 18, 2010, at 11:25 AM, Santosh Srinivas wrote:
>
>> Strangely this is not working ... what am I doing wrong here?
>>
>>> tDate <- FnO_Data$Date[1]
>>> tDate
>> [1] 20090101
>>> as.Date(c(tDate),format="%Y%m%d")
>> [1] NA
>
> ?sasDate
>
> as.Date does not take numeric arguments.

That's not correct. A numeric argument returns an NA ; at least with  
zoo loaded, an origin of "1970-01-01" is implicitly assumed.

 > as.Date(1)
[1] "1970-01-02"
 > as.Date(20090101)
[1] "56974-10-30"

I would have seen this had I used methods(as.Date).

R version 2.11.1 Patched (2010-06-14 r52281)
[R.app GUI 1.35 (5590) x86_64-apple-darwin9.8.0]
snipped sessionInfo()
other attached packages:
  [1] zoo_1.6-4

-- 
David.


> Try:
>
> > as.Date(as.character(tDate), format="%Y%M%d")
> [1] "2009-09-01"
>
> -- 
>
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> 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
West Hartford, CT



More information about the R-help mailing list