R 分组计算所有发生的事件
我想在R中模拟以下sql查询:R 分组计算所有发生的事件,r,R,我想在R中模拟以下sql查询: 从tablename组中按1,2选择CAST(calltime作为日期)、x、AVG(AAT)rev、COUNT(*)发生次数 result should be like this: date x rev occurances 2016-12-30 col 56.32 3652 2016-12-30 col_NA 24.69 2006
从tablename组中按1,2选择CAST(calltime作为日期)、x、AVG(AAT)rev、COUNT(*)发生次数代码>
result should be like this:
date x rev occurances
2016-12-30 col 56.32 3652
2016-12-30 col_NA 24.69 2006
2016-12-30 dial 32.20 4236
2016-12-29 col 54.98 3762
2016-12-29 col_NA 24.32 2105
2016-12-29 dial 31.93 4165
. . . .
. . . .
. . . .
我正在使用以下R代码:
#dfsub is the dataframe that has the table
dfsub$aat = as.numeric(dfsub$aat)
dfsub$calltime = as.Date(dfsub$calltime)
bycalltime_x <- summarise(group_by(dfsub,calltime,x), rev = mean(aat))
#dfsub是包含表的数据帧
dfsub$aat=as.numeric(dfsub$aat)
dfsub$calltime=as.Date(dfsub$calltime)
bycalltime_x这对于stackoverflow.com来说更像是一个问题……但是,您希望使用dplyr
,并且可以像这样使用管道操作符%%>%
:
dfsub%>%groupby(dfsub,calltime,x)%>%summary(avg=mean(aat))
如果我理解正确:)欢迎来到StackOverflow!请阅读相关信息以及如何给出建议。这将使其他人更容易帮助你。