gpt4 book ai didi

R xts : . 索引中的 001 毫秒

转载 作者:行者123 更新时间:2023-12-02 08:49:14 26 4
gpt4 key购买 nike

看起来 POSIXlt 允许毫秒精度规范,但我在 xts 对象中设置 .001 毫秒索引值时遇到问题:

> options(digits.secs = 3)
> data(sample_matrix)
> sample.xts = xts(sample_matrix, rep(as.POSIXlt("2012-03-20 09:02:50.001"), 180))
> head(sample.xts, 10)
Open High Low Close
2012-03-20 09:02:50.000 50.03978 50.11778 49.95041 50.11778
2012-03-20 09:02:50.000 50.23050 50.42188 50.23050 50.39767
2012-03-20 09:02:50.000 50.42096 50.42096 50.26414 50.33236
2012-03-20 09:02:50.000 50.37347 50.37347 50.22103 50.33459
2012-03-20 09:02:50.000 50.24433 50.24433 50.11121 50.18112
2012-03-20 09:02:50.000 50.13211 50.21561 49.99185 49.99185
2012-03-20 09:02:50.000 50.03555 50.10363 49.96971 49.98806
2012-03-20 09:02:50.000 49.99489 49.99489 49.80454 49.91333
2012-03-20 09:02:50.000 49.91228 50.13053 49.91228 49.97246
2012-03-20 09:02:50.000 49.88529 50.23910 49.88529 50.23910
> sample.xts = xts(sample_matrix, rep(as.POSIXlt("2012-03-20 09:02:50.002"), 180))
> head(sample.xts, 10)
Open High Low Close
2012-03-20 09:02:50.002 50.03978 50.11778 49.95041 50.11778
2012-03-20 09:02:50.002 50.23050 50.42188 50.23050 50.39767
2012-03-20 09:02:50.002 50.42096 50.42096 50.26414 50.33236
2012-03-20 09:02:50.002 50.37347 50.37347 50.22103 50.33459
2012-03-20 09:02:50.002 50.24433 50.24433 50.11121 50.18112
2012-03-20 09:02:50.002 50.13211 50.21561 49.99185 49.99185
2012-03-20 09:02:50.002 50.03555 50.10363 49.96971 49.98806
2012-03-20 09:02:50.002 49.99489 49.99489 49.80454 49.91333
2012-03-20 09:02:50.002 49.91228 50.13053 49.91228 49.97246
2012-03-20 09:02:50.002 49.88529 50.23910 49.88529 50.23910

为什么001毫秒设置失败?

最佳答案

POSIXct 表示是 Ripley 教授的一个非常聪明的“黑客”,他将标准的双字节单词分解为通常的“自纪元以来的天数”的“仍然足够”的表示,加上“适当的精度亚秒数据'。计算结果约为一微秒:

R> now <- Sys.time()
R> for (x in seq(1,10)) print(difftime(now, now + 10^-x))
Time difference of -0.0999999 secs
Time difference of -0.00999999 secs
Time difference of -0.000999928 secs
Time difference of -9.98974e-05 secs
Time difference of -1.00136e-05 secs
Time difference of -9.53674e-07 secs
Time difference of 0 secs
Time difference of 0 secs
Time difference of 0 secs
Time difference of 0 secs
R>

关于R xts : . 索引中的 001 毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9787509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com