Search code examples
rdatecsvquantmod

Date information disappears when save to CSV


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

Solution

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