如何在R中总结5分钟的间隔 [英] How to sum 5 minute intervals in R
问题描述
我有一个数据集,其中包含 6 个不同站点的每分钟降水记录.我想对每个站每 5 分钟进行一次总结.这些是我的数据集的前 5 行(我总共有 17280 行):
I have a dataset with precipitation records for every minute, for 6 different stations. I'd like to have summations for every 5 minutes, for every station. These are the first 5 rows of my dataset (in total I have 17280 rows):
P_alex P_hvh P_merlijn P_pascal P_thurlede P_tosca date
0 0 0 0 0 0 2011-06-27 22:00:00
0 1 5 2 0 0 2011-06-27 22:01:00
0 0 0 0 0 0 2011-06-27 22:02:00
0 6 2 3 0 0 2011-06-27 22:03:00
0 0 0 0 0 0 2011-06-27 22:04:00
我试图在互联网上寻求帮助,但找不到对我有帮助的答案.
I tried to find help on the internet, but I can not find an answer that helps me.
我还需要每小时求和,为此我使用以下代码,但是如果您想进行其他求和,此代码无用
I also needed houlry sums, for that I use the following code, but this code is useless if you want to make other summations
uur_alex = tapply(disdro$P_alex, as.POSIXct(trunc(disdro$date, "hour")), sum)
现在我想要一个代码,我可以用来进行不同的求和,所以需要 5 分钟(如问题所示),但也需要半小时.我希望有人可以帮助我.
Now I would like a code I could use to make different summations, so for 5 minutes (as in the question), but also for half an hour. I hope somebody can help me.
推荐答案
您可以使用 zoo
包中的 rollapply
来实现此目的.例如,
you can use rollapply
from the zoo
package to achieve this. For example,
require(zoo)
tester <- data.frame(x=1:100,y=1:100)
output <- rollapply(tester,5,(sum),by=5,by.column=TRUE,align='right')
这篇关于如何在R中总结5分钟的间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!