I think you will find that the 'catastrophic loss of significance' is in the printing at the default level. Try print(x, digits=15).

On Sun, 3 Aug 2008, cls59 wrote:


Hello all,

I have a quick question about formatting date strings..

Datetime strings, methinks. If you do just want days, use as.Date not as.POSIXct.

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.

______________________________________________
R-help@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.


--
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@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.

Reply via email to