Sliding time intervals for time series data in R

前端 未结 2 1094
野的像风
野的像风 2020-12-13 21:26

I am trying to extract interesting statistics for an irregular time series data set, but coming up short on finding the right tools for the job. The tools for manipulating

2条回答
  •  半阙折子戏
    2020-12-13 21:34

    Here's what I was suggeting, but I'm not sure it exactly answers your question

    #Picking up where your code left off
    library(xts)
    library(TTR)
    x <- .xts(vecZ, vecTimes)
    xx <- na.locf(cbind(xts(, seq.POSIXt(from=start(x), to=end(x), by='sec')), x))
    x$means <- runMean(xx, n=180)
    out <- x[!is.na(x[, 1]), ]
    tail(out)
    
                                      x     means
    1969-12-31 18:28:17.376141 0.2053531 0.1325938
    1969-12-31 18:28:17.379140 0.2101565 0.1329065
    1969-12-31 18:28:17.619840 0.2139770 0.1332403
    1969-12-31 18:28:17.762765 0.2072574 0.1335843
    1969-12-31 18:28:17.866473 0.2065790 0.1339608
    1969-12-31 18:28:17.924270 0.2114755 0.1344264
    

提交回复
热议问题