0

I'm trying to retrieve stock prices with the following code using quantmod. The code below allows me to retrieve what I need. However, when I export the CSV file, the date column (first column) appears only as a sequence of numbers. To be clear, it's fine in R when I open a data frame, but changes when exported.

from.dat <- as.Date("01/01/12", format="%m/%d/%y") 
to.dat <- as.Date("12/31/17", format="%m/%d/%y") 
getSymbols("GOOG", src="yahoo", from = from.dat, to = to.dat)
write.csv(GOOG, file = "Googletest.csv", row.names = TRUE)

Any ideas how to get the code to include a date? - Mike

1 Answers1

0

This seems like a duplicate from this one. The problem boils down to the fact your file is a xts object. Either way, just replace the last line by

write.csv(as.data.frame(GOOG), file = "Googletest.csv", row.names = TRUE)

and you'll be fine.

MauOlivares
  • 161
  • 1
  • 8