1

I am trying to export into a new dataframe the number of days within a 16 day time period where temperatures exceed 22.3. I want to complete this for all of the possible 16 day periods within June-August (ie 1st June-16th June, 2nd June-17th June etc etc )

I have daily temperatures for June, July and August (for one year specifically at the moment) with a column for date in this date format: 2090-06-01. I have used the following code and tibbletime : df1<-filter_time(df, time_formula = '2090-06-01' ~ '2090-06-16') to export a 16 day period and then I can get the sum of days above a certain threshold from that.

** My problem is how to loop this through all 75 of the possible 16 day periods in the time period of June-August. **

Here is a simplified version:

structure(list(Date = structure(c(43981, 43982, 43983, 43984, 
43985, 43986, 43987, 43988, 43989, 43990), class = "Date"), Nor_MM = c(22.58582103, 
20.43654256, 17.37954095, 18.12772066, 19.53053131, 23.25153522, 
24.52291687, 24.83597434, 24.67915157, 24.22688304)), row.names = 6441:6450, class = "data.frame")

Dates are in 2090-06-01 format. How would I go about calculating the sum of days within each possible 4 day period which are above 20 degrees?

Ellie Rose
  • 23
  • 3
  • 2
    You need to do a "rolling sum". [Here's a popular question on rolling sums](https://stackoverflow.com/q/30153835/903061). If you need more help than that, please make a small reproducible example and share some sample data: you could share 10 rows of data and ask how to do this operation with 4-day periods instead of 16-day periods, which would be a nice simplified version of the problem. The nicest way to share data is with `dput()` - `dput(your_data[1:10, ])` will make a copy/pasteable version of the first 10 rows of `your_data`, including all class and structure information. – Gregor Thomas Jun 28 '23 at 14:27
  • Thankyou, I have attached a simplified version to the question as I couldn't quite work it out from the example given – Ellie Rose Jun 29 '23 at 09:47

0 Answers0