chron represents times as a fraction of a day using doubles so seconds
cannot necessarily be represented exactly thus this is an example of
FAQ 7.31:
http://cran.r-project.org/doc/manuals/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
Try this:
library(chron)
tt <- c("09:45:00", "09:45:01", "09:45:04",
"09:45:05", "09:45:06",
"09:45:08", "09:45:11", "09:45:12",
"09:45:14")
tt <- times(tt)
> trunc(tt[3] + times("00:00:01"), "sec") == tt[4]
[1] TRUE
See R News 4/1.
On Tue, Aug 26, 2008 at 2:05 AM, <zengzhenxing at gmail.com>
wrote:> Full_Name: Zeng, zhenxing
> Version: 2.7.1 (2008-06-23)
> OS: windows XP
> Submission from: (NULL) (158.182.1.30)
>
>
> Dear Author
>
> I have run into a trouble in using chron package
> The data frame: a
> date time_fut expiry_day bid ask trade_day
> 1 2004-09-01 09:45:00 2004-10 12860 12889 38
> 2 2004-09-01 09:45:01 2004-10 12885 12890 38
> 3 2004-09-01 09:45:04 2004-10 12883 12887 38
> 4 2004-09-01 09:45:05 2004-10 12878 12886 38
> 5 2004-09-01 09:45:06 2004-10 12881 12887 38
> 6 2004-09-01 09:45:08 2004-10 12881 12882 38
> 7 2004-09-01 09:45:11 2004-10 12881 12884 38
> 8 2004-09-01 09:45:12 2004-10 12882 12884 38
> 9 2004-09-01 09:45:14 2004-10 12882 12883 38
>
> I use the package chron
>
> a$time_fut<-times(a$time_fut)
> a$date<-as.Date(a$date)
> a$expiry_day<-as.character(a$expiry_day)
>
> any(am$time_fut[2]==(am$time_fut[1]+times("00:00:01")))
> the answer: True
> any(a$time_fut[5]==(a$time_fut[4]+times("00:00:01")))
> [1] TRUE
> any(am$time_fut[4]==(am$time_fut[3]+times("00:00:01")))
> the answer: False
> But, the right answer should be true
>
> I don't know why, I am using the R version: 2.7.1
> attached please find the data.
>
> Thank you
>
> Best wishes
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>