I want to sum 11 and 12 month of a particular year with 1, 2, and 3 month of the subsequent year. I am using the following code
library(tidyverse)
library(seas)
library(lubridate)
## get mscdata from "seas" packages
data(mscdata)
dat <- (mksub(mscdata, id=1108447))
dat %>%
mutate(Year = year(date),
Month = month(date),
Day = day(date)) %>%
group_by(Year, Month) %>%
summarise(Monthly = sum(precip)) %>%
subset(Month %in% c(11, 12, 1, 2, 3)) %>%
group_by(Year) %>%
summarise(try = sum(Monthly))
The above code sums up 1, 2, 3, 11 and 12 of each year.
Year try
<dbl> <dbl>
1 1975 826.
2 1976 576.
3 1977 584.
4 1978 536
5 1979 653.
6 1980 942.
7 1981 739.
8 1982 853.
9 1983 990.
10 1984 927.
My expected output should be
Year try
1976 850.3
1977 396.6
1978 652.6
1979 508.7
1980 764.4
1981 897.4
1982 912.4
1983 880.3
1984 964.8
1985 620