I have daily time-series data for 60 years about the presence and absence of rainfall for 400 stations. The data is in the following format where, in the second column, 1 indicates presence and 0 indicate absence:
Date Rainfall
---------------------
1981-01-01 0
1981-01-02 0
1981-01-03 0
1981-01-04 1
1981-01-05 0
1981-01-06 1
1981-01-07 1
1981-01-08 1
1981-01-09 0
1981-01-10 0
1981-01-11 1
1981-01-12 1
1981-01-13 1
1981-01-14 1
1981-01-15 1
1981-01-16 0
.......... .
Now I have to calculate the number of consecutive wet days for each year when at least 3 consecutive days received rainfall and the longest consecutive days of rainfall in a year. If 3 or more than 3 consecutive days (any number) received rainfall I will consider it as a single event.
My output will be like this
Year No of consecutive wet-days longest consecutive wet-days
1981 2 5
.
.
How can we do this in R? If I can solve for a station, I can iterate for all stations in R.
Thank you in advance for your help :)