将小时步骤值的15分钟步长的总计值 [英] Aggregate values of 15 minute steps to values of hourly steps

查看:102
本文介绍了将小时步骤值的15分钟步长的总计值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框架,如下所示:

I have a data frame that looks like this:

     Timedate              TotalSolar_MW
20  2013-06-01 04:45:00     13.0
21  2013-06-01 05:00:00     41.7
22  2013-06-01 05:15:00     81.8
23  2013-06-01 05:30:00    153.0
24  2013-06-01 05:45:00    270.7
25  2013-06-01 06:00:00    429.3
26  2013-06-01 06:15:00    535.4

Timedate是 POSIXlt , Total_Solar是 numeric 。时间步长是从6月1日0:00到6月24日24:00间隔15分钟。

"Timedate" is POSIXlt, and "Total_Solar" is numeric. The time steps are in 15 minute intervals from June 1, 0:00 to June 24, 24:00.

现在我想要 aggregate 小时数据的小时数据,例如2013-06-01 06:00:00 934.8MW(81.8MW + 153.0MW + 270.7MW + 429.3MW;从05:15至06:00)

Now I want to aggregate the quarter hourly data to hourly steps e.g. 2013-06-01 06:00:00 934.8MW (81.8MW + 153.0MW + 270.7MW + 429.3MW; from 05:15 to 06:00)

I尝试这样做:

 Sum <-aggregate(Total_Solar_Gesamt$TotalSolar_MW, 
          list(as.POSIXlt(Total_Solar_Gesamt$Timedate)$hour), FUN=sum)

但是它返回整个数据的汇总小时数据框架,并给我一个新的数据框架与24行,并总结了MW每小时。

But it returns the aggregated hourly data of the whole data frame and gives me a new data.frame with 24 rows and the summed up MW for every hour.

如何更改结构,只有从一个小时缩小到一小时间隔?我试过一个for循环,但这也没有工作。另外子集不适合我。

How can I change the structure, only to reduce from a quarter hourly to a hourly interval? I tried a for loop but this also didn't work. Also subset didn't work for me.

感谢您的帮助!

推荐答案

使用时间序列时,建议您使用 xts 例如 hourly.apply

When working with time series, I suggest you work with xts package for this, and for example hourly.apply:

 library(xts)
 dat.xts <- xts(Total_Solar_Gesamt$TotalSolar_MW,
                as.POSIXct(otal_Solar_Gesamt$Timedate))
 hourly.apply(dat.xts,sum)

更一般的你可以使用 period.apply 这是( lapply 等价),例如每2小时汇总一次数据,您可以执行以下操作:

More general you can use period.apply which is (lapply equivalent) , for example to aggregate your data each 2 hours you can do the following:

 ends <- endpoints(zoo.data,'hours',2) 
 period.apply(dat.xts,ends ,sum)

这篇关于将小时步骤值的15分钟步长的总计值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆