这与your other question (?) 相同,可能的解决方案相同:
library(xts)
set.seed(42)
x <- xts(rnorm(1000000), as.POSIXct('2012-10-07') - (1000000:1) )
index(x) = index(x) - (9*3600)
x1 <- lapply ( split(x,'days'), function(one_day){ index(one_day) = index(one_day) + 9*3600; one_day } )
index(x) = index(x) + (9*3600)
这里是 x:
2012-09-25 10:13:20 1.3709584
2012-09-25 10:13:21 -0.5646982
2012-09-25 10:13:22 0.3631284
...
2012-10-06 23:59:57 0.7505021
2012-10-06 23:59:58 -0.4726833
2012-10-06 23:59:59 1.1356617
这里是 x1[1]:
2012-09-25 10:13:20 1.3709584
2012-09-25 10:13:21 -0.5646982
2012-09-25 10:13:22 0.3631284
...
2012-09-26 08:59:57 -0.7079315
2012-09-26 08:59:58 -0.2135840
2012-09-26 08:59:59 -1.8307128
x1[[2]]:
2012-09-26 09:00:00 2.3205603
2012-09-26 09:00:01 1.8911404
2012-09-26 09:00:02 -0.8547244
...
2012-09-27 08:59:57 -0.5731661
2012-09-27 08:59:58 -1.5224021
2012-09-27 08:59:59 -0.5316183
还有 x1[[12]]:
2012-10-06 09:00:03 0.9222899
2012-10-06 09:00:04 -0.2010127
2012-10-06 09:00:05 -1.8403161
...
2012-10-06 23:59:54 -0.5931701
2012-10-06 23:59:55 -1.1656284
2012-10-06 23:59:56 0.7000441
如果您想要另一种方法,您也可以更改时区:
Sys.setenv(TZ = "UTC")
library(xts)
set.seed(42)
x <- xts(rnorm(1000000), as.POSIXct('2012-10-07') - (1000000:1) )
indexTZ(x) = 'UTC+9'
x1 <- lapply ( split(x,'days'), function(one_day){ indexTZ(one_day) = 'UTC'; one_day } )
如果您上午 9 点的休息日实际上是夏令时的上午 8 点,那么您应该使用时区方法,因为 R 会自动为您进行夏令时调整。如果不是,我更喜欢以前的方法:然后我将准确描述我的意思,并且不容易受到时区数据库中的错误的影响。 (我认为 TZ 数据库在 Windows 上的工作方式也可能有所不同......我还没有机会测试它。)