R按取消分组日期在顶层汇总

时间:2019-04-07 22:41:11

标签: r

我有一个R代码,我试图在不取消时间分组的情况下总结代码,但是R无法取消时间分组。

我的桌子看起来像这样

Time    |Zone          |Main Station    |Sum of Value
25/03/2019 00:30    |BW1    |BANW   |4 
25/03/2019 00:30    |BW2    |BANW   |4 
25/03/2019 00:30    |BW3    |BANW   |4 
25/03/2019 00:30    |BW4    |BANW   |4 
25/03/2019 01:30        |BW1     |BANW    |2
25/03/2019 01:30        |BW3    | BANW  |  6.6
25/03/2019 01:30        |BW2    | BANW  |  7.2
25/03/2019 01:30        |gh1    | ty |  2
25/03/2019 01:30        |gh2     |ty   | 6.6
25/03/2019 01:30        |gh3    |ty   | 7.2

我正试图得到一张这样的桌子

Time              |Main Station |Sum of Value
25/03/2019 00:30        |BANW      |16  
25/03/2019 01:30       | BANW       |9.2     

我正在尝试为每个时间戳找到各个电台的所有区域之和。

当我汇总时,输出采用区域而不是站名的形式,并且数据透视表说无法合计时间,因为我不想按时间分组而不是按原样保留时间,而只求和各个电台的区域值。

还尝试使用lubridate软件包将时间转换为小时格式,但输出仍为Zone形式,并且出现有关小标题的警告。

1 个答案:

答案 0 :(得分:1)

dataset$Time <- as.character(dataset$Time)
dataset%>%group_by(Time,Main Station)%>%summarise(Sum of Value=sum(Sum of Value))

以上代码将根据您的要求运行。