I have daily sales data for multiple products in three stores. It looks something like this:
| item_id | store_id | category_id | dept_id | date | event_name | daiy_price |
|---|---|---|---|---|---|---|
| a | tx_1 | food | 1 | 2012/12/24 | 6 | |
| a | tx_1 | food | 1 | 2012/12/25 | christmas | 6 |
| a | tx_1 | food | 1 | 2012/12/26 | 6 | |
| a | tx_1 | food | 1 | 2012/12/27 | 7 | |
| a | tx_1 | food | 1 | 2012/12/28 | 7 | |
| b | tx_1 | food | 1 | 2012/12/24 | 6 | |
| b | tx_1 | food | 1 | 2012/12/25 | christmas | 6 |
| b | tx_1 | food | 1 | 2012/12/26 | 6 | |
| b | tx_1 | food | 1 | 2012/12/27 | 7 | |
| b | tx_1 | food | 1 | 2012/12/28 | 7 |
I want to round each week to the monday date using floor_date from lubridate package in R, then use group_by and summarise to compute weekly price average. However, i want each week to retain event_name if there is any during a particular week. Including event_name in group_by is not helpful since a day in a week may have an event but other days may not and they get grouped separately. Say each week starts on a monday and 2012/12/24 is a monday, how do i achieve this
| item_id | store_id | category_id | dept_id | date | event_name | weekly_avg_price |
|---|---|---|---|---|---|---|
| a | tx_1 | food | 1 | 2012/12/24 | christmas | 6.4 |
| b | tx_1 | food | 1 | 2012/12/24 | christmas | 6.4 |