Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

Re: [R] date arithmetic discrepancy

Berend Hasselman

2012-01-28

Replies: Find Java Web Hosting

Author LoginPost Reply

On 27-01-2012, at 21:45, Ty Canuck wrote:

> What accounts for the different result?
>
>> as.numeric(as.POSIXct("2012-01-13 08:10:00") - as.POSIXct("2012-01-13
> 00:00:00") , units='secs')
> [1] 29400
>
>> trunc(as.numeric(as.POSIXct("2012-01-13 08:10:00") -
> as.POSIXct("2012-01-13 00:00:00") , units='secs') )
> [1] 29399

See R FAQ 7.31

And try this

d1 <- as.numeric(as.POSIXct("2012-01-13 08:10:00") - as.POSIXct("2012-01-13 00:00:00") , units='secs')
d2 <- trunc(as.numeric(as.POSIXct("2012-01-13 08:10:00") - as.POSIXct("2012-01-13 00:00:00") , units='secs') )

sprintf("%.12f",d1)

Berend

______________________________________________
R-help@(protected)
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.
©2008 r-help.com - Jax Systems, LLC, U.S.A.