如何使用R中的write.table函数?
我正在尝试使用命令 write.table(ESH2, "c:/ESH2.txt", sep=",")
将对象保存到文本文件。问题是保存的时间序列不包含我下载的日期和时间值。我使用了包 twsInstrument 和命令 getBAT(ESH2)
使用命令 load(file = "C:/ESH2) 将其加载到 R 时获得的数据.Rdata")
ES.Bid.Price ES.Ask.Price ES.Trade.Price ES.Mid.Price ES.Volume
1323700200 1237.25 1237.50 1237.50 1237.375 6954
1324057980 1210.25 1210.50 1210.25 1210.375 3792
1324058040 1210.50 1211.00 1211.00 1210.750 3305
.........
.........
.........
1324058100 NA NA NA NA 823
attr(,".indexCLASS")
[1] POSIXct POSIXt
attr(,".indexTZ")
[1]
attr(,"from")
[1] 20111211 23:59:59
attr(,"to")
[1] 20111216 23:59:59
attr(,"src")
[1] IB
attr(,"updated")
[1] "2011-12-16 18:54:55 CET"
第一列应显示 Date_Time 而不是 1323700200。
我正在寻找一种每周下载一次数据并合并数据的简单方法。
ps 是的,我可以阅读教程/书籍来完成此任务,是的,我会这样做,但问题是我缺乏时间。我想在本周开始收集数据,因为交互式代理限制数据请求1 分钟数据 = 最多 5 天
。我感谢任何帮助和建议。
I am trying to save an object to a text file with the command write.table(ESH2, "c:/ESH2.txt", sep=",")
. The problem is that the saved time series doesn't contain date and time values that I downloaded. I used the package twsInstrument and the command getBAT(ESH2)
The data i have when loading it into R with the command load(file = "C:/ESH2.Rdata")
ES.Bid.Price ES.Ask.Price ES.Trade.Price ES.Mid.Price ES.Volume
1323700200 1237.25 1237.50 1237.50 1237.375 6954
1324057980 1210.25 1210.50 1210.25 1210.375 3792
1324058040 1210.50 1211.00 1211.00 1210.750 3305
.........
.........
.........
1324058100 NA NA NA NA 823
attr(,".indexCLASS")
[1] POSIXct POSIXt
attr(,".indexTZ")
[1]
attr(,"from")
[1] 20111211 23:59:59
attr(,"to")
[1] 20111216 23:59:59
attr(,"src")
[1] IB
attr(,"updated")
[1] "2011-12-16 18:54:55 CET"
The first column should show Date_Time and not 1323700200.
I am searching for an easy way to download the data once per week and merge the data.
p.s Yes i can read through the tutorials/books to accomplish this and yes i will do it but the problem is my lack of time. I want to start collecting the data this week cause interactive brokers is limiting data requests 1min data = 5DAYS maximum
. I am thankful for any help and suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能有一个 xts 或 Zoo 对象,并且需要使用 write.zoo 函数。如果我对“ESH2”对象的结构的理解是正确的,那么您称为“第一列”的数据实际上是行名,用zoo/xts的说法是“索引”,而可以使用 < 访问数据code>coredata 是一个矩阵对象。
从 read/write.zoo 页面上的示例中:
You probably have an xts or zoo object and need to use the
write.zoo
function. If I'm right about the structure of the "ESH2" object, then the data that you are calling the "first column" is actually the rownames which in zoo/xts parlance is the "index" while the data can be accessed withcoredata
and is a matrix object.From the examples on the read/write.zoo page:
如果您的唯一目标是保存该对象,以便将来可以再次从 R 访问它,那么 using
将为您做到这一点。您可以稍后使用 load: 再次获取对象:
但正如评论中提到的,如果您需要帮助让 write.table 或 write.csv 解决方案正常工作,那么您需要提供更多信息。
If your only goal is to save the object so that you can access it from R again in the future then using
will do that for you. You can get the object back again later by using load:
But as mentioned in the comments if you want help getting the write.table or write.csv solution to work then you'll need to provide more information.