I can't get your code to run, but this will get the same info. from the St. Louis Fed:
library(quantmod)
library(zoo)
symbols=c('NIKKEI225')
getSymbols(symbols,src='FRED')
df <- as.data.frame(NIKKEI225)
df <- cbind(date=as.Date(rownames(df)),df)
write.csv(df,file="Ndata.csv, row.names=F)
The problem is that getSymbols(...)
returns a timeseries object, where the times are implicit. So when you save you just get the "time index", rather than a data-time variable. The code above makes the times explicit by putting them in a column of the dataframe, and explicitly setting them to class Date.
As @GSee points out in the comment below, this is another, better way:
df <- data.frame(date=index(NIKKEI225),NIKKEI225)
write.csv(df,file="Ndata.csv, row.names=F)