Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
rxts:毫秒索引_R_Xts - Fatal编程技术网

rxts:毫秒索引

rxts:毫秒索引,r,xts,R,Xts,如何创建索引包含毫秒的xts对象?我在POSIXlt帮助页中找不到任何格式规范,但indexFormat()中有一个到%OS的格式规范 更新 基于Gavin zoo答案的xts示例: > options(digits.secs = 3) > data(sample_matrix) > sample.xts = xts(sample_matrix, Sys.time() + seq(0, by = 0.1, length = 180)) > head(sample.xts)

如何创建索引包含毫秒的xts对象?我在POSIXlt帮助页中找不到任何格式规范,但indexFormat()中有一个到%OS的格式规范

更新

基于Gavin zoo答案的xts示例:

> options(digits.secs = 3)
> data(sample_matrix)
> sample.xts = xts(sample_matrix, Sys.time() + seq(0, by = 0.1, length = 180))
> head(sample.xts)
                            Open     High      Low    Close
2012-03-20 08:49:02.820 50.03978 50.11778 49.95041 50.11778
2012-03-20 08:49:02.920 50.23050 50.42188 50.23050 50.39767
2012-03-20 08:49:03.020 50.42096 50.42096 50.26414 50.33236
2012-03-20 08:49:03.120 50.37347 50.37347 50.22103 50.33459
2012-03-20 08:49:03.220 50.24433 50.24433 50.11121 50.18112
2012-03-20 08:49:03.320 50.13211 50.21561 49.99185 49.99185

这适用于packagezoo,因此我怀疑它也适用于xts,因为后者基于前者

> ## create some times with milliseconds
> times <- Sys.time() + seq(0, by = 0.1, length = 10)
> times
 [1] "2012-03-19 22:10:57.763 GMT" "2012-03-19 22:10:57.863 GMT"
 [3] "2012-03-19 22:10:57.963 GMT" "2012-03-19 22:10:58.063 GMT"
 [5] "2012-03-19 22:10:58.163 GMT" "2012-03-19 22:10:58.263 GMT"
 [7] "2012-03-19 22:10:58.363 GMT" "2012-03-19 22:10:58.463 GMT"
 [9] "2012-03-19 22:10:58.563 GMT" "2012-03-19 22:10:58.663 GMT"
> ZOO <- zoo(1:10, order = times)
> index(ZOO)
 [1] "2012-03-19 22:10:57.763 GMT" "2012-03-19 22:10:57.863 GMT"
 [3] "2012-03-19 22:10:57.963 GMT" "2012-03-19 22:10:58.063 GMT"
 [5] "2012-03-19 22:10:58.163 GMT" "2012-03-19 22:10:58.263 GMT"
 [7] "2012-03-19 22:10:58.363 GMT" "2012-03-19 22:10:58.463 GMT"
 [9] "2012-03-19 22:10:58.563 GMT" "2012-03-19 22:10:58.663 GMT"
这是使用

> opts <- options(digits.secs = 3)

>选择加文,只是为了清楚地说明一下:毫秒是在索引的小数部分指定的?是的,很抱歉没有解释问题的
POSIXt
方面
Sys.time()
返回毫秒精度&我以0.1秒递增的顺序添加。R只是在给定默认选项时对您隐藏这一点。在实际时间中,如果第二个是十进制,则
后面的位表示次秒位,R将使用输入中的
%S
占位符处理该问题。在输出时,
%S
将删除亚秒位,但
%OSn
占位符将保留它们
n
是一个范围为
0:6
的数字,用于指定次秒位数。如果缺少
n
,则使用
getOption(“digits.secs”)
。@RobertKubrick请阅读
?strftime
,了解所用占位符及其含义的详细信息。
> opts <- options(digits.secs = 3)