每小时汇总意味着基于复合字段表达式 [英] Aggregate hourly means based on compound field expression

查看:145
本文介绍了每小时汇总意味着基于复合字段表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在类似于这个数据框中计算 x 的小时平均值:

<$ p $小时日日月​​x
1 10 22 31 12 2013 18.3
2 30 22 31 12 2013 16.5
3 50 22 31 12 2013 15.7
4 10 23 31 12 2013 16.7
5 30 23 31 12 2013 18.0
6 50 23 31 12 2013 18.1
7 10 0 1 1 2014 17.4
8 30 0 1 1 2014 15.4
9 50 0 1 1 2014 16.9

我对聚合函数,但没有运气。所以我想要的是如果小时天的值计算 x 的均值 month year 是相同的。输出应该如下所示:

 小时日月份x 
1 22 31 12 2013 16.83333
2 23 31 12 2013 17.60000
3 0 1 1 2014 16.56667


解决方案 $ p
$ b

  require(dplyr)

mydf%> ;%
group_by(年,月,日,小时)%>%
汇总(平均值=平均值(x))


I am trying to calculate the hourly mean of x in a data frame similar to this:

  min hour day month year    x
1  10   22  31    12 2013 18.3
2  30   22  31    12 2013 16.5
3  50   22  31    12 2013 15.7
4  10   23  31    12 2013 16.7
5  30   23  31    12 2013 18.0
6  50   23  31    12 2013 18.1
7  10    0   1     1 2014 17.4
8  30    0   1     1 2014 15.4
9  50    0   1     1 2014 16.9

I have tried different things with the aggregate function but without luck. So what I want is to calculate the mean of x if the value of hour, day, month, year are the same. The output should be like below:

  hour day month year        x
1   22  31    12 2013 16.83333
2   23  31    12 2013 17.60000
3    0   1     1 2014 16.56667

解决方案

Give this a try..

require(dplyr)

mydf %>%
   group_by(year, month, day, hour) %>%
   summarise (average = mean(x))

这篇关于每小时汇总意味着基于复合字段表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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