flOw
flOw

Reputation: 13

Importing timeSeries from csv file into R with correct dates

I have looked all over the internet to find an answer to my problem and failed.

I am using R with the Rmetrics package.

I tried reading my own dataset.csv via the readSeries function but sadly the dates I entered are not imported correctly, now every row has the current date.

I tried using their sample data sets, exported them to csv and re-imported an it creates the same problem.

You can test it using this code:

data <- head(SWX.RET[,1:3])
write.csv(data, file="myData.csv")
data2 <- readSeries(file="myData.csv",header=T,sep=",")

If you now check the data2 time series you will notice that the row date is the current date.

I am confused why this is and what to do to fix it.

Your help is much appreciated!

Upvotes: 1

Views: 3833

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368181

This can be achieved with the extra option row.names=FALSE to the write.csv() functions; see its help page for details. Here is a worked example:

R> fakeData <- data.frame(date=Sys.Date()+seq(-7,-1), value=runif(7))
R> fakeData
        date    value
1 2011-02-14 0.261088
2 2011-02-15 0.514413
3 2011-02-16 0.675607
4 2011-02-17 0.982817
5 2011-02-18 0.759544
6 2011-02-19 0.566488
7 2011-02-20 0.849690
R> write.csv(fakeData, "/tmp/fakeDate.csv", row.names=FALSE, quote=FALSE)
R> readSeries("/tmp/fakeDate.csv", header=TRUE, sep=",")
GMT
              value
2011-02-14 0.261088
2011-02-15 0.514413
2011-02-16 0.675607
2011-02-17 0.982817
2011-02-18 0.759544
2011-02-19 0.566488
2011-02-20 0.849690
R> 

Upvotes: 3

Related Questions