保存到CSV时,日期信息消失 [英] Date information disappears when save to CSV

查看:974
本文介绍了保存到CSV时,日期信息消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从互联网中提取一些数据,然后将其导出到CSV文件,但是我在CSV文件中丢失了我的日期信息。我不知道为什么。我是R的新人,所以请保持反应简单。这里是我的代码:

 库(quantmod)
getSymbols(SPY,from =2012-01- 01,to =2012-12-31)
write.csv(SPY,C:/SPY.csv)


解决方案

因为SPY是一个xts / zoo对象,所以它会做的诀窍:



替换:

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



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


I am trying to pull some data in from the internet and then export it to a CSV file, but I am loosing my date information in the CSV file. I can't figure out why. I'm new to R so please keep responses simple. Here is my code:

Library(quantmod)
getSymbols("SPY", from = "2012-01-01", to = "2012-12-31")
write.csv(SPY, "C:/SPY.csv")

解决方案

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=",")

这篇关于保存到CSV时,日期信息消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆