write.csv conversion problem
On Thu, Mar 10, 2016 at 11:58 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
On Thu, Mar 10, 2016 at 4:43 AM, Peter Neumaier <peter.neumaier at gmail.com> wrote:
Hi all, I am writing a matrix (typeof = double) into a CSV file with write.csv. My first column of the matrix is a date in the form yyyy-mm-dd hh:mm:ss:
a_fetchdata[1,0]
2016-02-09 07:30:00
typeof(a_fetchdata[1,0])
[1] "double"
Your a_fetchdatra object isn't a matrix. It looks like it's either an xts or a zoo object. I'm not sure how you concluded that the first column is a date-time, based on the result of extracting the 0-th column.
You are totally right: it is an xts object. I probably mis-phrased it but I meant to say that the format inside the cell is yyyy-mm-dd while purely focusing on the problem of losing that date format with the column being converted into an integer...sorry bad language.
My CSV file contains a sequence of integers (from 1 to x) instead of the expected date. How can I prevent that conversion to happen when writing into CSV?
Use write.zoo.
All problems solved now:
- I am reading/writing from/to zoo objects and casting back to xts with
as.xts:
write.zoo("myfile.csv", sep = ",", quote = FALSE)
myData <- as.xts(read.zoo("myFile.csv",sep=",",tz="",header=T))
Thanks to everyone.
Peter