POSIXct 和 xts 中的时区,从 R 中的 GMT 转换 [英] time zones in POSIXct and xts, converting from GMT in R
本文介绍了POSIXct 和 xts 中的时区,从 R 中的 GMT 转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 xts
对象中有一堆 1 分钟的回报,索引为 POSIXct
,时区为 GMT.回报在纽约证券交易所,所以我想转换为东部时区,但我想正确处理夏令时.这样做的最佳方法是什么?我在 EST 时区和 EDT 时区之间有点困惑.我希望我的时间在冬季和夏季正确转换为纽约时间.
I have a bunch of 1 minute returns in an xts
object with the index being POSIXct
and time zone being GMT. The returns are on NYSE so I would like to convert to the eastern time zone but I would like to take care of the daylight savings time properly. What is the best way of doing this? I am a bit confused between the EST timezone and the EDT timezone. I would like my times to convert properly to the NY time in winter and summer.
推荐答案
使用 indexTZ<-
和 America/New_York
时区
> tail(SPY)
SPY.Bid.Price SPY.Ask.Price SPY.Trade.Price SPY.Mid.Price SPY.Volume
2012-08-09 19:54:00 140.47 140.48 140.48 140.475 2372
2012-08-09 19:55:00 140.46 140.47 140.46 140.465 5836
2012-08-09 19:56:00 140.47 140.48 140.48 140.475 2538
2012-08-09 19:57:00 140.47 140.48 140.47 140.475 2209
2012-08-09 19:58:00 140.48 140.49 140.49 140.485 4943
2012-08-09 19:59:00 140.58 140.59 140.58 140.585 16780
> indexTZ(SPY) <- "America/New_York"
> tail(SPY)
SPY.Bid.Price SPY.Ask.Price SPY.Trade.Price SPY.Mid.Price SPY.Volume
2012-08-09 15:54:00 140.47 140.48 140.48 140.475 2372
2012-08-09 15:55:00 140.46 140.47 140.46 140.465 5836
2012-08-09 15:56:00 140.47 140.48 140.48 140.475 2538
2012-08-09 15:57:00 140.47 140.48 140.47 140.475 2209
2012-08-09 15:58:00 140.48 140.49 140.49 140.485 4943
2012-08-09 15:59:00 140.58 140.59 140.58 140.585 16780
Warning message:
timezone of object (America/New_York) is different than current timezone (GMT).
这篇关于POSIXct 和 xts 中的时区,从 R 中的 GMT 转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文