【发布时间】:2016-04-02 07:37:57
【问题描述】:
我一直在努力对有关月份和时间的数据进行平均。 我使用的数据是 6 个月(比如 1 月到 6 月),一列中间隔 15 分钟,第二列中时间段的值。 我使用下面提到的 cod 对从分钟间隔到每小时间隔的数据进行了平均:
library(xts)
data<-read.csv("C:/Users/naman.nagar/Downloads/JAVA &R/15_Minute_Site_ Avg.csv",header=TRUE,stringsAsFactors = FALSE)
data$Timestamp<-as.POSIXct(strptime(cognos_data$Timestamp,format="%Y-%m-%d %H:%M"))
data.xts<-xts(x=cognos_data$Wanamaker,cognos_data$Timestamp)
ep<-endpoints(data.xts,"hours")
period.apply(data.xts,ep,mean)
我使用上面的代码得到的数据是:
2015-12-19 10:15:00 1602
2015-12-19 11:15:00 1608
2015-12-19 12:15:00 1590
2015-12-19 13:15:00 1590
2015-12-19 14:15:00 1344
2015-12-19 15:15:00 1338
2015-12-19 16:15:00 1338
2015-12-19 17:15:00 1338
2015-12-19 18:15:00 1338
2015-12-19 19:15:00 1392
2015-12-19 20:15:00 1368
2015-12-19 21:15:00 1302
2015-12-19 22:15:00 1302
2015-12-19 23:15:00 1266
2015-12-20 00:15:00 1248
2015-12-20 01:15:00 1254
2015-12-20 02:15:00 1218
2015-12-20 03:15:00 1188
现在从这些数据中,我希望每月平均数据为:
2015-12 10:00:00 1389
2015-12 11:00:00 1390
2015-12 12:00:00 1400
2015-12 13:00:00 1396
意思是说我在每小时级别(例如 12:00:00)获得了整个 12 月的平均数据,以获得整个月份特定时间的平均值。
请帮忙。 提前致谢!
【问题讨论】: