【发布时间】:2019-07-11 08:54:59
【问题描述】:
我有称为 ddata 的大数据。它的日期字段范围从 2014 年到 2018 年。我想按 12 个月的时间段(从特定月份开始,例如 2014 年 4 月至 2015 年 3 月等)对每个县的案例进行分组。
我编写了仅在日历年执行结果的给定代码。但我想在任何 12 个月期间执行类似的结果,即从任何一个月开始(例如 2014 年 4 月至 2015 年 3 月、2015 年 4 月至 2016 年 3 月等......)
ddata <- ddata %>%
select(ID, Disease, DateReported, County) %>%
mutate(calendar_year = year(Date)) %>%
mutate(month = month(DateReported)) %>%
filter(calendar_year >=2014) %>%
group_by(County, calendar_year) %>%
summarize(cases = n()) %>%
spread(calendar_year, cases)
【问题讨论】:
-
欢迎来到 StackOverflow。看看这里和这里stackoverflow.com/questions/50702804/…stackoverflow.com/questions/33877714/…