Convert a irregular time series to a regular time series

前端 未结 2 1011
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 22:06

I am having a problem when converting irregular time series to regular time series. Below a simplified example can be found:

require(zoo)
t <- as.characte         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 22:12

    It's not a bug. There are 1,461 days spanning the 4 years in your time series. And it doesn't work for me the first time I run it. as.Date(t,"%Y") doesn't know what month/day to use to make a date, so it uses today's month/day. That does not make for reproducible analysis. Try this instead:

    t <- c(1981,1984,1985)
    d <- c(1,3,6)
    z <- zoo(d,t)
    z <- merge(z,zoo(,c(1981,1982,1983,1984,1985)))
    ts.d <- as.ts(z)
    

    Which yields:

    > ts.d
    Time Series:
    Start = 1981 
    End = 1985 
    Frequency = 1 
    [1]  1 NA NA  3  6
    

提交回复
热议问题