Skip to content

write.csv conversion problem

3 messages · Joshua Ulrich, Peter Neumaier

#
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:
2016-02-09 07:30:00
[1] "double"


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?

Thanks
Peter
#
On Thu, Mar 10, 2016 at 4:43 AM, Peter Neumaier
<peter.neumaier at gmail.com> wrote:
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.
Use write.zoo.

  
    
#
On Thu, Mar 10, 2016 at 11:58 AM, Joshua Ulrich <josh.m.ulrich at gmail.com>
wrote:
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.
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