【问题标题】:endpoints are always in UTC/GMT端点始终采用 UTC/GMT
【发布时间】:2017-06-30 09:46:11
【问题描述】:

我认为端点是通过将索引转换为 UTC 来生成的。我希望端点在每小时 9:00/10:00 等(或在我特定定义的时间间隔,比如在 9:30/10:30 等)发生变化。

在下面的示例中,对象“a”是 UTC,端点创建于 4:55,5:55 等,对象“b”创建于 10:25,11:25 等。我正在寻找解决方案以指定方式提供端点,与时区无关。

有什么简单的机制可以做到这一点吗?

> head(a)
                       Open    High     Low   Close
2008-01-01 04:30:00 6114.05 6126.65 6111.35 6111.35
2008-01-01 04:35:00 6110.50 6130.65 6110.50 6128.90
2008-01-01 04:40:00 6128.70 6130.15 6123.15 6123.55
2008-01-01 04:45:00 6124.85 6131.90 6123.45 6131.55
2008-01-01 04:50:00 6132.20 6134.45 6128.70 6131.20
2008-01-01 04:55:00 6132.25 6134.85 6132.25 6134.45
> indexTZ(a)
   TZ 
"UTC" 
> a[endpoints(a,on="hours")]
                       Open    High     Low   Close
2008-01-01 04:55:00 6132.25 6134.85 6132.25 6134.45
2008-01-01 05:55:00 6136.70 6136.70 6132.15 6134.45
2008-01-01 06:55:00 6157.65 6157.65 6153.20 6154.25
2008-01-01 07:55:00 6155.65 6157.60 6155.00 6157.25
2008-01-01 08:55:00 6143.25 6143.90 6137.50 6138.05
2008-01-01 09:55:00 6150.95 6151.65 6147.50 6149.20
2008-01-02 04:55:00 6113.40 6120.90 6089.00 6089.00
2008-01-02 05:55:00 6086.15 6087.25 6068.80 6068.95
2008-01-02 06:55:00 6098.10 6108.25 6098.10 6105.85
2008-01-02 07:05:00 6107.40 6107.40 6093.70 6094.80
> head(b)
                       Open    High     Low   Close
2008-01-01 10:00:00 6114.05 6126.65 6111.35 6111.35
2008-01-01 10:05:00 6110.50 6130.65 6110.50 6128.90
2008-01-01 10:10:00 6128.70 6130.15 6123.15 6123.55
2008-01-01 10:15:00 6124.85 6131.90 6123.45 6131.55
2008-01-01 10:20:00 6132.20 6134.45 6128.70 6131.20
2008-01-01 10:25:00 6132.25 6134.85 6132.25 6134.45
> indexTZ(b)
            TZ 
"Asia/Kolkata" 
> b[endpoints(b,on="hours")]
                       Open    High     Low   Close
2008-01-01 10:25:00 6132.25 6134.85 6132.25 6134.45
2008-01-01 11:25:00 6136.70 6136.70 6132.15 6134.45
2008-01-01 12:25:00 6157.65 6157.65 6153.20 6154.25
2008-01-01 13:25:00 6155.65 6157.60 6155.00 6157.25
2008-01-01 14:25:00 6143.25 6143.90 6137.50 6138.05
2008-01-01 15:25:00 6150.95 6151.65 6147.50 6149.20
2008-01-02 10:25:00 6113.40 6120.90 6089.00 6089.00
2008-01-02 11:25:00 6086.15 6087.25 6068.80 6068.95
2008-01-02 12:25:00 6098.10 6108.25 6098.10 6105.85
2008-01-02 12:35:00 6107.40 6107.40 6093.70 6094.80
> 

感谢和问候

湿婆孙库

【问题讨论】:

    标签: r time-series xts endpoints


    【解决方案1】:

    endpoints 始终以 UTC 计算偏移量。作为最终用户,您无能为力。但是您可以通过比较 1 小时端点和 30 分钟端点来解决它。

    x <- .xts(1:12, seq(0, by=600, length.out=12), tzone="Asia/Kolkata")
    x[endpoints(x, "hours")]
    #                     [,1]
    # 1970-01-01 06:20:00    6
    # 1970-01-01 07:20:00   12
    hourEndpointsTZ30 <- function(x) {
      h <- endpoints(x, "hours", 1)
      m <- endpoints(x, "minutes", 30)
      c(0, setdiff(m, h), last(m))
    }
    x[hourEndpointsTZ30(x)]
    #                     [,1]
    # 1970-01-01 05:50:00    3
    # 1970-01-01 06:50:00    9
    # 1970-01-01 07:20:00   12
    

    【讨论】:

    • 你好约书亚,非常感谢。
    猜你喜欢
    • 2014-10-11
    • 2020-06-02
    • 2010-12-09
    • 2011-05-16
    • 2011-07-31
    • 2018-05-05
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    相关资源
    最近更新 更多