First, clarify the data structure and simulation goal: each iteration randomly assigns half the rows to a 10% price increase, then joins to a catalog and computes overall and per-category mean prices. Use a vectorized, dplyr-based approach with slice_sample, mutate, case_when, left_join, group_by, and summarise, wrapping the iteration in a function and using purrr::map_dfr to avoid for-loops. Finally, summarise the simulation results to report empirical mean and SD for each statistic.
Pro tip: Mention that you would set the seed once at the start and use slice_sample with replace = FALSE to ensure exactly half the rows are selected, and note that using purrr::map_dfr keeps the code clean and scalable while satisfying the no-for-loop requirement.
Confirm the structure of the prices and catalog tables, the definition of 'half the rows', and how categories are derived. Discuss the need for reproducibility with set.seed(2025) and the requirement to scale to a million items.
Create a function that takes the prices and catalog data, uses slice_sample to randomly select half the rows to keep at original price, and mutate with case_when to increase the other half by 10%. Then left_join to catalog and compute overall mean price and mean price by category using group_by and summarise.
Use purrr::map_dfr (or replicate with simplify) to apply the function 1,000 times, binding the results into a single data frame with one row per simulation. Ensure set.seed(2025) is called before the iterations.
From the simulation output, compute the empirical mean and standard deviation for the overall mean price and for each category's mean price using summarise(across(...)) or pivot_longer and group_by.
Explain how the dplyr pipeline is vectorized and memory-efficient, and mention potential optimizations like using data.table or disk-based processing if the data exceeds memory, while still adhering to the dplyr requirement.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.