3

The data looks like

           Time  Set1    Set2   
10:19:38.551629 16234   16236   
10:19:41.408010 16234   16236   
10:19:47.264204 16234   16236   

I am trying to load this into zoo.

orig <- read.zoo("~/sample.txt",sep="",header=TRUE,index.column=1,format="%H:%M:%S.%6f")

Error in read.zoo("~/sample.txt", sep = "", header = TRUE, index.column = 1,  : 
  index has 3 bad entries at data rows: 1 2 3 ...

I have checked all the relevant posts 1. R issue with rounding milliseconds 2. Milliseconds puzzle when calling strptime in R 3. How to parse milliseconds in R?

However this does not help. Any Suggestions

Community
  • 1
  • 1
shoonya
  • 292
  • 1
  • 10
  • 1
    Notice that the answers to all those posts use `format = '%H:%M:%OS'` or `format = '%H:%M:%OS6'` – GSee Jun 21 '12 at 12:27

1 Answers1

4

You want the index to be a time class such as POSIXct or POSIXlt. Also, your format argument wasn't quite right. Try this

read.zoo("~/sample.txt", header = TRUE, format="%H:%M:%OS", FUN=as.POSIXct)

Which, for the sample data provided, gives

read.zoo(text="           Time  Set1    Set2   
10:19:38.551629 16234   16236   
10:19:41.408010 16234   16236   
10:19:47.264204 16234   16236   ", header = TRUE, format="%H:%M:%OS", FUN=as.POSIXct)
#                            Set1  Set2
#2012-06-21 10:19:38.551629 16234 16236
#2012-06-21 10:19:41.408010 16234 16236
#2012-06-21 10:19:47.264204 16234 16236
GSee
  • 48,880
  • 13
  • 125
  • 145
  • 1
    Note that `read.zoo(..., tz = "")` or similar but using `tz="GMT"`, say, will cause `read.zoo` to default to POSIXct with the time zone indicated. – G. Grothendieck Jun 21 '12 at 17:05
  • Set1 Set2 2012-06-22 10:19:38 16234 16236 2012-06-22 10:19:41 16234 16236 2012-06-22 10:19:47 16234 16236. I also set the options(digits=6), but still no microsecond timestamp in the read.zoo – shoonya Jun 22 '12 at 03:39
  • 1
    `options(digits.secs=6)`. Run that, then you'll see microseconds. – GSee Jun 22 '12 at 03:45
  • Thanks GSee. Zoo seems to be pretty powerful. – shoonya Jun 22 '12 at 04:16