在没有时区的 R 中创建日期和时间序列

Create sequence of dates and times in R without time zones

我需要在 R 中创建一个日期和时间序列,以 15 分钟为周期递增。 目前,我正在这样做:

datestimes=seq(as.POSIXlt("2011-01-01 00:00:00"), as.POSIXlt("2015-09-30 23:45:00"), by="15 min")

我应该一年中每次阅读一次。问题是,由于它针对 BST 进行了调整,我得到了 10 月某些日期的两个值。

anm=aggregate(datestimes, by=list(datestimes$datestimes), FUN=length)
anm[which(anm$datestimes>1),]

                   Group.1 datestimes X.Date.
28993  2011-10-30 01:00:00          2       2
28994  2011-10-30 01:15:00          2       2
28995  2011-10-30 01:30:00          2       2
28996  2011-10-30 01:45:00          2       2
63933  2012-10-28 01:00:00          2       2
63934  2012-10-28 01:15:00          2       2
63935  2012-10-28 01:30:00          2       2
63936  2012-10-28 01:45:00          2       2
98873  2013-10-27 01:00:00          2       2
98874  2013-10-27 01:15:00          2       2
98875  2013-10-27 01:30:00          2       2
98876  2013-10-27 01:45:00          2       2
133813 2014-10-26 01:00:00          2       2
133814 2014-10-26 01:15:00          2       2
133815 2014-10-26 01:30:00          2       2
133816 2014-10-26 01:45:00          2       2

我尝试使用 as.chron 命令,因为它不使用时区,但它不允许增加 15 分钟,这正是我需要的。

也许试试这个(UTC 时区不应允许任何重复):

datestimes=seq(as.POSIXlt("2015-09-01 00:00:00", tz="UTC"), 
               as.POSIXlt("2015-10-30 23:45:00", tz="UTC"), 
               by="15 min")

The problem is that since it is adjusting for BST, I get two values for certain dates in October.

那是因为 'fall back'(夏令时调整的助记符,在秋季增加一个小时)发生在 人类时间 下,这就是你得到的 默认,除非你覆盖它。

R> seq(as.POSIXlt("2012-10-28 00:00:00", tz="UTC"), 
+      as.POSIXlt("2012-10-28 03:00:00", tz="UTC"), by="15 min")
 [1] "2012-10-28 00:00:00 UTC" "2012-10-28 00:15:00 UTC"
 [3] "2012-10-28 00:30:00 UTC" "2012-10-28 00:45:00 UTC"
 [5] "2012-10-28 01:00:00 UTC" "2012-10-28 01:15:00 UTC"
 [7] "2012-10-28 01:30:00 UTC" "2012-10-28 01:45:00 UTC"
 [9] "2012-10-28 02:00:00 UTC" "2012-10-28 02:15:00 UTC"
[11] "2012-10-28 02:30:00 UTC" "2012-10-28 02:45:00 UTC"
[13] "2012-10-28 03:00:00 UTC"
R> 

我在这里展示的例子涵盖了与上面相同的子集但没有回退,因为我们现在将 UTC 作为时区。而且UTC一直在建设没有夏令时调整。