【发布时间】:2016-10-18 08:25:21
【问题描述】:
所以我得到了想要转换为 xts 的数据,以便我可以使用 quantmod 绘制它。 (是15m图表)
> sample
Date Open High Low Close Vol.at.Price Volume
515 2016-06-15 pm 1:15:00 1.7381 1.7600 1.710 1.7399 1.7399 176000
516 2016-06-15 pm 1:30:00 1.7389 1.7400 1.725 1.7350 1.7350 152900
517 2016-06-15 pm 1:45:00 1.7350 1.7650 1.720 1.7550 1.7550 179900
518 2016-06-15 pm 2:00:00 1.7550 1.7600 1.740 1.7500 1.7500 130800
519 2016-06-15 pm 2:15:00 1.7550 1.7800 1.745 1.7800 1.7800 188400
520 2016-06-15 pm 2:30:00 1.7800 1.7899 1.730 1.7300 1.7300 256700
521 2016-06-15 pm 2:45:00 1.7300 1.7800 1.730 1.7664 1.7664 151900
522 2016-06-15 pm 3:00:00 1.7600 1.7700 1.740 1.7600 1.7600 74100
523 2016-06-15 pm 3:15:00 1.7501 1.8000 1.750 1.7850 1.7850 232300
524 2016-06-15 pm 3:30:00 1.7900 1.8200 1.760 1.7600 1.7600 183300
525 2016-06-15 pm 3:45:00 1.7600 1.7700 1.730 1.7400 1.7400 151600
526 2016-06-15 pm 4:00:00 1.7400 1.7599 1.650 1.7150 1.7150 443500
527 2016-06-15 pm 4:15:00 1.7100 1.7100 1.710 1.7100 1.7100 4628
528 2016-06-15 pm 6:30:00 1.7100 1.7100 1.710 1.7100 1.7100 2000
529 2016-06-15 pm 7:00:00 1.6900 1.6900 1.680 1.6900 1.6900 1050
530 2016-06-15 pm 8:00:00 1.6900 1.6900 1.690 1.6900 1.6900 100
> class(sample)
[1] "data.frame"
起初,我认为使用 xts 函数可以完成这项工作,但后来我意识到它只是减少了几分钟的部分。
> sampled.after<-xts(sample[2:ncol(sample)],as.Date(sample$Date))
> sampled.after
Open High Low Close Vol.at.Price Volume
2016-06-15 1.7381 1.7600 1.710 1.7399 1.7399 176000
2016-06-15 1.7389 1.7400 1.725 1.7350 1.7350 152900
2016-06-15 1.7350 1.7650 1.720 1.7550 1.7550 179900
2016-06-15 1.7550 1.7600 1.740 1.7500 1.7500 130800
2016-06-15 1.7550 1.7800 1.745 1.7800 1.7800 188400
2016-06-15 1.7800 1.7899 1.730 1.7300 1.7300 256700
2016-06-15 1.7300 1.7800 1.730 1.7664 1.7664 151900
2016-06-15 1.7600 1.7700 1.740 1.7600 1.7600 74100
2016-06-15 1.7501 1.8000 1.750 1.7850 1.7850 232300
2016-06-15 1.7900 1.8200 1.760 1.7600 1.7600 183300
2016-06-15 1.7600 1.7700 1.730 1.7400 1.7400 151600
2016-06-15 1.7400 1.7599 1.650 1.7150 1.7150 443500
2016-06-15 1.7100 1.7100 1.710 1.7100 1.7100 4628
2016-06-15 1.7100 1.7100 1.710 1.7100 1.7100 2000
2016-06-15 1.6900 1.6900 1.680 1.6900 1.6900 1050
2016-06-15 1.6900 1.6900 1.690 1.6900 1.6900 100
如何将其转换为时间序列以便绘制蜡烛图?
【问题讨论】:
-
as.Date仅返回时间戳的日期部分。使用as.POSIXct保留完整的时间戳。 -
除了显示 EDT 外,它仍然给我相同的结果。有没有其他办法?
标签: r datetime timestamp time-series quantmod