R:聚合时间序列数据返回 NA [英] R: Aggregating time series data returns NA
本文介绍了R:聚合时间序列数据返回 NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 xts 以 5 分钟的方式聚合数据:
I'm trying to aggreagate data by 5 minute means by using xts:
library(xts)
data <- read.csv("C:/Users/User/Documents/data.csv")
times <- data$Time
X <- as.POSIXct(times)
X <- as.xts(X)
DataTable <- period.apply(X, endpoints(X, "minutes", 5), mean)
问题是,如果打印出DataTable",则表明聚合没有起作用,聚合分数为空(NA).
The problem is, if print out "DataTable", it shows that the aggregation didn't work, the aggregation scores are empty (NA).
2016-08-28 21:26:32 NA
2016-08-28 21:29:05 NA
2016-08-28 21:30:57 NA
2016-08-28 21:34:31 NA
2016-08-28 21:35:22 NA
2016-08-28 21:37:31 NA
2016-08-28 21:40:15 NA
2016-08-28 21:43:59 NA
2016-08-28 21:48:01 NA
2016-08-28 21:48:58 NA
2016-08-28 21:49:14 NA
2016-08-28 22:40:45 NA
2016-08-28 23:40:45 NA
这是输入文件:https://www.dropbox.com/s/epkbk770ajksqnb/data.csv?dl=0
有人知道我做错了什么吗?
Anybody know what I'm doing wrong?
推荐答案
问题是你把 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))
这篇关于R:聚合时间序列数据返回 NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文