2010-11-28 37 views
0

我想用微秒定時索引解析csv。 所以,我寫了這樣的代碼:再經過Rxt中的顯示時間索引

t<-read.zoo("test", index.column = 1, sep=",",header=TRUE, format="%Y-%m-%d %H:%M:%OS") 
t.xts<-as.xts(t) 

,我試圖顯示這個,但我看不出對指數的時間信息。

> t.xts[1:10,4] 
      drate 
2010-09-28 " -149" 
2010-09-28 " -269" 
2010-09-28 " -358" 
2010-09-28 " -358" 
2010-09-28 " -239" 
2010-09-28 " -149" 
2010-09-28 " -149" 
2010-09-28 " -149" 
2010-09-28 " -119" 
2010-09-28 " -149" 

我試過選項(digits.secs = 6),但沒有奏效。

回答

3

如果您可以從CSV文件中提供幾行文字,這將有所幫助。設置options(digits.secs=6)適合我。您也可以嘗試使用indexFormat手動設置格式。

> x <- .xts(1:5, 1:5+runif(5)) 
> x 
        [,1] 
1969-12-31 18:00:01 1 
1969-12-31 18:00:02 2 
1969-12-31 18:00:03 3 
1969-12-31 18:00:04 4 
1969-12-31 18:00:05 5 
> indexFormat(x) <- "%Y-%m-%d %H:%M:%OS3" 
> x 
         [,1] 
1969-12-31 18:00:01.915 1 
1969-12-31 18:00:02.002 2 
1969-12-31 18:00:03.134 3 
1969-12-31 18:00:04.981 4 
1969-12-31 18:00:05.204 5 
> indexFormat(x) <- "%Y-%m-%d %H:%M:%OS" 
> options(digits.secs=6) 
> x 
          [,1] 
1969-12-31 18:00:01.914681 1 
1969-12-31 18:00:02.001752 2 
1969-12-31 18:00:03.134311 3 
1969-12-31 18:00:04.981147 4 
1969-12-31 18:00:05.204021 5