[R] Convert date to decimal days
cls59
sharpsteen at mac.com
Sun Aug 3 20:10:01 CEST 2008
Hello all,
I have a quick question about formatting date strings..
I am currently debugging some Matlab code someone else wrote and since it is
so bad that I have to go through it line by line I figured that I would just
rewrite the thing in R.
The code produces plots of wave spectra with decimal days since the Epoch as
the x axis and wave period as the Y axis. I am able to convert the date
stamp in the input file to a POSIXct object with the following call:
date = as.POSIXct(header[[1]][2],tz='GMT',format='%Y%m%d_%k')
date
"2008-07-11 03:00:00 GMT"
So every thing looks groovy, using as.double(date) gives me the number of
seconds since the epoch which reproduces the correct date when fed to date
-u -r on the command line.
However, I can't seem to find a clean way of converting the date to decimal
days since the epoch. Using
as.double(date)/86400
Gives:
14071.12
Which is a catastrophic loss of significance, the number should be 14071.125
I tried playing around with the format command to see if I could get R to
format the date differently, but no luck.
Any suggestions?
-Charlie
--
View this message in context: http://www.nabble.com/Convert-date-to-decimal-days-tp18800462p18800462.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list