6

我有以下 xts 矩阵:

> options(digits.secs = 6)
> set.seed(1234)
> xts(1:10, as.POSIXlt(1366039619, tz="EST", origin="1970-01-01") + rnorm(10, 500000, 250000)/1000000)
                           [,1]
2013-04-15 10:26:58.913576    4
2013-04-15 10:26:59.198234    1
2013-04-15 10:26:59.277491   10
2013-04-15 10:26:59.356315    7
2013-04-15 10:26:59.358887    9
2013-04-15 10:26:59.363342    8
2013-04-15 10:26:59.569357    2
2013-04-15 10:26:59.607281    5
2013-04-15 10:26:59.626514    6
2013-04-15 10:26:59.771110    3
Warning message:
timezone of object (EST) is different than current timezone ().

我需要每 100 毫秒生成一次时间序列条目,其中包含该期间的最后一个值。例如:

                           [,1]
2013-04-15 10:26:58.000000    4
2013-04-15 10:26:59.100000    4
2013-04-15 10:26:59.200000    1
2013-04-15 10:26:59.300000    10
2013-04-15 10:26:59.400000    8
...

请注意最后一个条目如何携带 8,即 0.300000 到 .399999 期间的最后一个条目。

4

1 回答 1

7

我不确定这是否适用于 Windows,因为对亚秒精度的支持很差,但这适用于 Ubuntu。

library(xts)
options(digits.secs=6)
set.seed(1234)
x <-  xts(1:10, as.POSIXlt(1366039619, tz="EST", origin="1970-01-01")
  + rnorm(10, 500000, 250000)/1000000)
ti <- trunc(index(x))
ms <- rep(seq(min(ti),max(ti),by="s"), each=10)+0:9/10
a <- merge(x,ms,fill=na.locf)[ms]

您会注意到,您处理此问题的方式与您需要从不规则数据创建规则 xts 系列的任何其他实例相同。不过这有点困难,因为生成亚秒级序列更困难。

于 2013-04-23T22:01:36.120 回答