Skip to content

write.csv conversion problem

2 messages · roger bos, Martin Maechler

#
Peter,

Dates are always stored as integers, so that is expected. You would need to use as.character() to convert the date before you output it to the file, but then it won't be of type double. 

Also, thee is a general r-help list where these types of questions should go. 

Thanks,,

Roger
On March 10, 2016, at 5:44 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:
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


_______________________________________________
R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
#
> Peter,

    > Dates are always stored as integers, so that is expected. 

but what you say, Roger, is not correct.  They *are* integer
valued, but they are double --- so that they will not suffer
from integer overflow for dates in the distant past or future:
[1] "2016-03-10"
 num 16870
 ^^^

Martin Maechler, ETH Zurich

    > You would need to use as.character() to convert
    > the date before you output it to the file, but then it
    > won't be of type double.
    

    > Also, thee is a general r-help list where these types of questions should go. 

    > Thanks,,

    > Roger
> On March 10, 2016, at 5:44 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"


    > 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

    > [[alternative HTML version deleted]]

    > _______________________________________________
    > R-SIG-Finance at r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
    > -- Subscriber-posting only. If you want to post, subscribe first.
    > -- Also note that this is not the r-help list where general R questions should go.
    > _______________________________________________
    > R-SIG-Finance at r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
    > -- Subscriber-posting only. If you want to post, subscribe first.
    > -- Also note that this is not the r-help list where general R questions should go.