I have big data called ddata. It has date field ranging from 2014 to 2018. I want to group the cases from each county by 12-month period(starting from specific month eg. April 2014- March 2015, and so on..).
I wrote given code that executes the result only for the calendar year. but I want to execute similar result for any 12-month period i.e. starting at any month (e.g. April 2014 to March 2015, April 2015 to March 2016 and so on..)
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)