【发布时间】:2018-10-22 22:55:42
【问题描述】:
在 R 中运行代码后,我看到 xts 对象
使用write.table(myresult, "myresult.csv", sep=","),我在A列中获得了带有升序数字作为行名的csv文件。
我希望日期,类似于 xts 对象,改为显示在 A 列中。如何做到这一点?
【问题讨论】:
在 R 中运行代码后,我看到 xts 对象
使用write.table(myresult, "myresult.csv", sep=","),我在A列中获得了带有升序数字作为行名的csv文件。
我希望日期,类似于 xts 对象,改为显示在 A 列中。如何做到这一点?
【问题讨论】:
您需要使用一个知道 xts 和 zoo 对象具有的索引的函数。例如write.zoo():
library(xts)
data(sample_matrix)
x <- as.xts(sample_matrix)
x <- round(x*100)
write.zoo(head(x), sep = ",")
# "Index","Open","High","Low","Close"
# 2007-01-02,5004,5012,4995,5012
# 2007-01-03,5023,5042,5023,5040
# 2007-01-04,5042,5042,5026,5033
# 2007-01-05,5037,5037,5022,5033
# 2007-01-06,5024,5024,5011,5018
# 2007-01-07,5013,5022,4999,4999
【讨论】: