[R] Summary: as.POSIXct

Brian Beckage Brian.Beckage at uvm.edu
Sat Mar 6 04:59:38 CET 2004


Suggestions from both Prof Brian Ripley and Gabor Grothendiec solved 
my problem.

 From Prof Ripley:

>This is a problem of your OS: your example works on all of mine.
>
>Can't you change the origin in chron?  If not, you should certainly be
>able to do
>
>as.POSIXct(strptime(as.character(testDATES), "%m/%d/%y"))

This still resulted in NA's on my system.

>
>Here's what I think you can do most easily:
>
>shift <- julian(1,1,1970, origin=c(month = 12, day = 30, year = 1899))
>as.POSIXct(chron(dates=unclass(testDATES) - shift))

But this worked.

 From Gabor Grothendiec:

>At any rate, one idea is to create the chron dates
>relative to the default origin like this:
>
>  > testDATES<-c(35947,35971,36004,36008,36053,36066)
>>  testDATES.chron <- chron("12/30/1899") + testDATES
>  > as.POSIXct(testDATES.chron)
>[1] "1998-05-31 20:00:00 Eastern Daylight Time"
>[2] "1998-06-24 20:00:00 Eastern Daylight Time"
>[3] "1998-07-27 20:00:00 Eastern Daylight Time"
>[4] "1998-07-31 20:00:00 Eastern Daylight Time"
>[5] "1998-09-14 20:00:00 Eastern Daylight Time"
>[6] "1998-09-27 20:00:00 Eastern Daylight Time"
>
>Does that make any difference on your system?


This worked on my machine as well.  I'm not sure why these solutions 
avoided the previous NA's, but I guess it had to do with my use of 
the 'origin' argument within chron on my particular os...

Thanks again,
Brian





Thanks,
Brian




-- 
*********************************************************************
Brian Beckage
Department of Botany
University of Vermont
Marsh Life Science Building
Burlington, VT 05405

Phone:  802 656-0197
Fax  :  802 656-0440
email:  Brian.Beckage at uvm.edu
web  :  www.uvm.edu/~bbeckage




More information about the R-help mailing list