2011-02-11 61 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)) 
相关问题