【发布时间】:2017-09-28 08:53:24
【问题描述】:
我在这里解决了一个非常相似的问题how to sum data by month and store them in the first day of the month
与上述帖子唯一不同的是,我的真实data.frame有300个变量,需要按月分组和求和。
类似这样的:
date gauge1 gauge2 gauge3
1937-02-19 25.768334 23.98 111.3
1937-02-20 24.918828 21.987 33.9
1937-02-21 24.069322 19.96 18.981
期望的输出:
date gauge1 gauge2 gauge3
1937-02-01 3328.98 2229.0 11541.3
1937-03-01 222.19 1176.8 1098.8
1937-04-01 1124.8 3395.15 1558.9
根据我尝试过的@jeremycg 回答:
library(dplyr)
qfile %>% mutate(monthyear = as.character(format(date, "%m-%Y"))) %>%
arrange(date) %>%
group_by(monthyear) %>%
summarise(date=date[1], flow = sum(df[, c(2:4)])
但它不起作用。
任何帮助将不胜感激。
谢谢
【问题讨论】:
-
为了让您的问题对其他人有用,请解释为什么
dplyr尝试失败。谢谢。 -
我不知道为什么它不起作用..对不起
-
您收到错误消息了吗?
-
是的,但不记得了。对不起