Start by clarifying the date window and the definition of net revenue (gross minus refunds). Then, build the solution step-by-step: compute daily net revenue per channel, identify each user's first purchase and refund status, calculate the 3-day rolling sum, and finally assemble the two tidy data frames with the required columns.
Pro tip: Always validate your results with small, hand-checked examples and ensure you handle edge cases like refunds without matching purchases or users with no purchases. Also, use dplyr's window functions and joins efficiently to avoid loops.
Confirm the date window, the definition of net revenue (e.g., refunds subtract from revenue on the refund date or the original purchase date?), and the structure of the transactions, refunds, and users tables. Identify key columns like transaction_id, user_id, channel, amount, date, and refund_id.
Filter transactions and refunds to the date window, then compute daily gross revenue per channel from transactions and daily refunds per channel from refunds. Join these and calculate net revenue as gross minus refunds, ensuring all dates and channels are represented (use complete() or tidyr::complete if needed).
For each user, find the earliest transaction date (first purchase) within the window. Then, check if that specific transaction was fully refunded by the window end by joining with refunds and comparing refund amounts to the transaction amount.
Using the daily net revenue per channel, apply a rolling sum over a 3-day window (e.g., with zoo::rollsum or slider::slide_dbl) grouped by channel, ensuring the window is based on consecutive dates (fill missing dates with 0 net revenue).
Create two data frames: one with daily net revenue per channel and its 3-day rolling sum, and another with each user's first purchase date and a flag indicating if that first order was fully refunded. Ensure column names and types match the required structure.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.