Efficient Data Transformation using dplyr
Instruction: Demonstrate how to perform a complex data transformation using dplyr, including filtering, selecting, and summarizing data.
Context: This question evaluates the candidate's proficiency with the dplyr package for data manipulation, an essential skill for efficient data analysis in R.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Chain filtering, projection and grouped summarization, and use the actual column name consistently. Define how missing amounts and grouping keys are handled.
library(dplyr) sales_data <- data.frame(store_id = c("A", "A", "A", "B"), year = c(2020, 2020, 2020, 2020), product_category = c("X", "X", "Y", "X"), sales_amount = c(10, NA, NA, 99)) summary_data <- sales_data |> filter(store_id == "A", year...