2011-02-11 29 views

回答

5

試試這個:

data.frame(Year = c(floor(time(z) + .01)), Month = c(cycle(z)), z) 

as.data.frame(cbind(Year = floor(time(z) + .01), Month = cycle(z), z)) 
2

您可以提取從TS與index()指數(從動物園包)

zindex <- index(z) 
zdf <- data.frame(Year = trunc(zindex), Month = (zindex - trunc(zindex)) * 12, z) 

或生成的日期與

Year = rep(1961:1969, each = 12)[1:100] 
Month = rep(1:12, times = 9)[1:100] 
+0

我想有一個函數來做到'X - TRUNC(x)的`但是我畫一個空白的那一刻... – 2011-02-11 20:31:46

+0

`指數()`不是基本函數,所以你應該指定它在動物園包中。 – 2011-02-11 20:37:18

0

類似的解決方案的序列@ jonw的,但使用xts:

x <- as.xts(z) 
d <- data.frame(Year=.indexyear(x)+1900, Month=.indexmon(x)+1, coredata(x)) 
相關問題