Date information disappears when save to CSV

蓝咒 提交于 2019-11-30 23:05:53

as SPY is a xts/zoo object this will do the trick:

replace:

write.csv(SPY, "C:/SPY.csv")

with

write.zoo(SPY,"C:/SPY.csv",index.name="Date",sep=",")
DariusS

Try:

write.csv(SPY, file= "SPY.csv", row.names = index(SPY))

Are you sure that the date information is being lost? If you are using MS-Excel to open the .CSV, it may be that Excel is munging your data.

If you do str(SPY) you get to see the inner structure of your xts object. The dates are in the index, not in the main data.

I use these three lines to save an xts object as a csv file:

#Convert to a data frame so it can be written to disk
d=as.data.frame(SPY)
d=cbind(datestamp=rownames(d),d)
write.csv(d,file="SPY.csv",row.names=F)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!