6

I have data in the format Date, Time, Value. Here is a sample:

04/01/2010,07:10,17159
04/01/2010,07:20,4877
04/01/2010,07:30,6078
04/01/2010,07:40,3105
04/01/2010,07:50,4073
04/01/2010,08:00,6986
04/01/2010,08:10,7906
04/01/2010,08:20,7681
04/01/2010,08:30,5665
04/01/2010,08:40,6631
04/01/2010,08:50,4633
04/01/2010,09:00,6346
04/01/2010,09:10,6444
04/01/2010,09:20,6324
04/01/2010,09:30,11696
04/01/2010,09:40,7667
04/01/2010,09:50,6375
04/01/2010,10:00,5934
04/01/2010,10:10,12626
04/01/2010,10:20,11674
04/01/2010,10:30,4660
04/01/2010,10:40,3831
04/01/2010,10:50,7089
04/01/2010,11:00,4548
04/01/2010,11:10,2590
04/01/2010,11:20,3334
04/01/2010,11:30,5171

I want to convert this to a Time Series of Value keeping the same format. i.e. I need to be able store the date and time components too. This is is because i want to "deseasonalize" the data.

I have tried

z <- read.csv("fileName", header=TRUE,sep=",")

but not sure what to do from here. Can anyone show me how to load into a time series object properly? Or is there another way to do this?

Thanks in advance

dayne
  • 7,504
  • 6
  • 38
  • 56
azuric
  • 2,679
  • 7
  • 29
  • 44
  • You may find [this introductory text](https://media.readthedocs.org/pdf/a-little-book-of-r-for-time-series/latest/a-little-book-of-r-for-time-series.pdf) useful. As a start at least. – Henrik Sep 16 '13 at 13:11

2 Answers2

9

You can use the zoo package. The code below was writen to be reproducible but in actual practice text="Lines" would be replaced with file="fileName". Also as shown in the question the Date field is ambiguous and you may need to adjust the percent codes if its not day/month/year.

library(zoo)

Lines <- "Date,Time,Value
04/01/2010,07:10,17159
04/01/2010,07:20,4877
04/01/2010,07:30,6078
04/01/2010,07:40,3105
"

z <- read.zoo(text = Lines, sep = ",", header = TRUE, 
       index = 1:2, tz = "", format = "%d/%m/%Y %H:%M")

which gives:

> z
2010-01-04 07:10:00 2010-01-04 07:20:00 2010-01-04 07:30:00 2010-01-04 07:40:00 
              17159                4877                6078                3105 
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
agstudy
  • 119,832
  • 17
  • 199
  • 261
  • Thanks a lot, this really helps. Think I need to invest in a couple of good R books. By the way your date format was correct. – azuric Sep 17 '13 at 06:28
-1

In addition to what has been mentioned as the answer, you can check this link (http://eclr.humanities.manchester.ac.uk/index.php/R_TSplots) which discusses the use of 'xts' in this case. I hope it helps.

Behrouz Beheshti
  • 1,053
  • 1
  • 10
  • 14
  • Please include the relevant part directly in the answer as a quote, as the URL might become 404 in the future. – Fusseldieb Sep 13 '22 at 19:05