2012-06-21 36 views
3

的數據看起來像動物園/ XTS微秒讀問題

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

我想這個加載到動物園。

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 ... 

我已經檢查了所有相關的帖子 1. R issue with rounding milliseconds 2. Milliseconds puzzle when calling strptime in R 3. How to parse milliseconds in R?

然而,這並沒有幫助。 任何建議

+1

注意,你所有那些帖子使用'格式=「%H:%M:%OS''或'格式='%H:%M:%OS6' – GSee

回答

4

你想索引是一個時間類,如POSIXctPOSIXlt。另外,你的論點並不完全正確。試試這個

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

其中,對提供的樣本數據,給出了

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 
+1

請注意,'read.zoo(...,tz =「」)'或類似的,但使用'tz =「GMT」',將導致'read.zoo '默認爲指定時區的POSIXct。 –

+0

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.我還設置了選項(數字= 6),但在read.zoo – shoonya

+1

'options(digits.secs = 6)'中仍然沒有微秒時間戳。運行它,然後你會看到微秒。 – GSee