I have calculated daily average and stored it in an object 'abc'. I want to calculate monthly average using abc. I am using following code in R. Could anyone please help me how to modify the existing code to make groups in summarize function to calculate monthly average. (Please note that I have used the same code to calculate hourly data using the grouping of 60mins.) But I do not understand how to change the 60mins grouping to grouping of days as per the month (30,31days). Also, another factor to consider in this is leap year. Is it possible to make grouping on the basis of month from Date (yyyy-mm-dd) data. Kindly help.
Code:
mn <- abc %>%
select(any_of(cn)) %>%
as_tibble() %>%
group_by(Time_sp = lubridate::floor_date(`Date/Time`, "60 mins")) %>%
mutate(Time_sp = format(Time_sp, "%Y-%m-%d %H:%M:%S+00")) %>%
summarise(across(where(is.numeric), ~ if(mean(is.na(.x)) > 0.8) NA else mean(.x, na.rm = TRUE)))
write.csv(mn, paste0(dirlist[idx],"_mn.csv"), row.names = FALSE)