且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

R:聚合时间序列数据返回 NA

更新时间:2023-02-26 19:59:42

问题是你把 X 作为聚合的参数而不是数字字段(例如 T1> 或 T2).

The problem was that you put X as the argument to aggregate rather than a numeric field (e.g. T1 or T2).

   library(xts)
    mydata    <- read.csv("data.csv")
    times     <- mydata$Time
    X         <- as.POSIXct(times)
    X         <- as.xts(X)
    period.apply(mydata$T1, INDEX = endpoints(X, "minutes", 5), function(x) mean(x, na.rm=T))