Slide 21
Slide 21 text
例2)予約履歴データに対象キャンペーン情報を付与
# Not Awesome
reservation |>
cross_join(campaign) |>
dplyr::filter(reserved_at >= starts_at & reserved_at <= ends_at) |>
select(!c(starts_at, ends_at))
# Awesome
campaign_expanded <- campaign |>
rowwise() |>
mutate(reserve_date = list(seq(date(starts_at), date(ends_at), by="day"))) |>
unnest(reserve_date)
reservation |>
mutate(reserve_date = date(reserved_at)) |>
left_join(campaign_expanded, by = "reserve_date",relationship = "many-to-many") |>
select(!reserve_date)