本文介绍了将1分钟的数据汇总为5分钟的平均数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是将每1分钟收集的数据汇总为5分钟平均值。
DeviceTime Concentration
6/20/2013 11:13
6/20/2013 11:14
6/20/2013 11:15
6/20/2013 11:16
6/20/2013 11:17
6/20/2013 11:18
6/20/2013 11:19
6/20/2013 11:20
6 / 20/2013 11:21
6/20/2013 11:22
6/20/2013 11:23
6/20/2013 11:24
6/20 / 2013 11:25
6/20/2013 11:26
6/20/2013 11:27
6/20/2013 11:28
...
我想要的结果是:
设备时间集中
/ pre>
6/20/2013 11:15
6/20/2013 11:20
6 / 20/2013 11:25
6/20/2013 11:30
6/20/2013 11:35
...
5分钟的平均值只是过去五分钟内集中度的简单平均值。
解决方案使用
dplyr
包,假设你的d ata存储在名为df
的数据框架中:require(dplyr )
df%>%
group_by(DeviceTime = cut(DeviceTime,休息=5分钟))%>%
总结(浓度=平均(浓度))
My question here is to aggregate the data collected at every 1-minute into 5-minute average.
DeviceTime Concentration 6/20/2013 11:13 6/20/2013 11:14 6/20/2013 11:15 6/20/2013 11:16 6/20/2013 11:17 6/20/2013 11:18 6/20/2013 11:19 6/20/2013 11:20 6/20/2013 11:21 6/20/2013 11:22 6/20/2013 11:23 6/20/2013 11:24 6/20/2013 11:25 6/20/2013 11:26 6/20/2013 11:27 6/20/2013 11:28
...
The result I want is like:
DeviceTime Concentration 6/20/2013 11:15 6/20/2013 11:20 6/20/2013 11:25 6/20/2013 11:30 6/20/2013 11:35 ...
The 5-minute average is just the simple average over the concentration in the past five minutes.
解决方案Using the
dplyr
package and assuming, your data is stored in a data frame nameddf
:require(dplyr) df %>% group_by(DeviceTime = cut(DeviceTime, breaks="5 min")) %>% summarize(Concentration = mean(Concentration))
这篇关于将1分钟的数据汇总为5分钟的平均数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!