I want to calculate the mean of the minimum temperature value (minTemp) between April 1st and April 5th for each year of a data set (montbrun).
I have tried simply filter(julianDays >= 091 & julianDays <= 095)
, but as I was expecting, it doesn't work cause it takes only the first values of the data set that fits to 091-095 values (in julian days).
In other words, my goal is to calculate mean, for every year of the data set between april (Month=4) 1st and 5th (Days= 1 to 5), but in julian days. What I don't know is how to code this when I have multiple years, months and all the julian days in a single year. Just to clarify, on a normal year, January 1st is 001 and December 31st is 365 in julian days.
Any idea how to code this?
My Data
montbrun <- structure(list(Year = c(2005, 2005, 2005, 2005, 2005, 2006, 2006,
2006, 2006, 2006, 2007, 2007, 2007, 2007, 2007, 2008, 2008, 2008,
2008, 2008), Month = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4), Day = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
1, 2, 3, 4, 5),Date/Time
= structure(c(1112313600, 1112400000,
1112486400, 1112572800, 1112659200, 1143849600, 1143936000,
1144022400, 1144108800, 1144195200, 1175385600, 1175472000,
1175558400, 1175644800, 1175731200, 1207008000, 1207094400,
1207180800, 1207267200, 1207353600), class = c("POSIXct", "POSIXt"),
tzone = "UTC"),
julianDays = c("091", "092", "093", "094", "095", "091",
"092", "093", "094", "095", "091", "092", "093", "094", "095",
"092", "093", "094", "095", "096"), minTemp = c(1, -5, -2,
-2, -6, 1, -9, 0, -7.5, -5, -7, 0.5, -2.5, -1.5, -10, -8,
-17.5, -8, -6.5, -5)), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"))
My Code
example <- montbrun %>%
group_by(Year) %>%
filter(Month == 4) %>%
filter(Day >= 1 & Day <= 5) %>%
summarise(mintemp = mean(minTemp))
If someone could help me with that, it would be fantastic !
Thanks !