I'm trying to do a smoothed mean on weeks, but need to do it on the +/- 1 week before and after the target week, and the overlap from week 52/53 to week 1 is giving me a few issues. I can hardcode it with a for loop and a few if statements and make it work, but I'm convinced there is a more elegant solution.
I'm looking for a data.frame output with two columns, weeks ranging 1:53 and where value is a smoothed mean. For week 1 it should average week 53, 1 and 2. For week 53 the average should consist of the values in week 52, 53 and 1. It would be great if it could be used as a summary function after a dplyr::group_by pipe.
This doesn't summarise the data.frame to distinct weeks but is "sliding" over the whole data. I'm looking for a solution that summarise into distinct weeks, but where the mean also includes the neighboring weeks.
The description might be a bit confusing. I'll change it a bit.
I wouldn't swear that I understand your goal, but I think you can summarise by week the smoothed means and make a composite mean (of means)
assuming you adopt my proposal, continue it with:
Yes, but my example data is overly simplified as I have a few hundred thousand observations in each week per year, so running the slider like that is not possible. I think I'll try to generalise the get_weeks function to be more like the slider function with "before" and "after" params.
Thanks for trying to help me though. It's much appriciated.