Hello!
I have a data where each part is associated with many models. Its like many to many relationship. I am trying to aggregate total sales of models per part without aggregating the sales of part itself as sales of part remains same for a given time. Example, Sales of Part A was 100 in Jan 2018 and Sales of Model 1& 2 was 1000 & 2000 respectively for the same time period and thus, total sales of models for part A was 3000 in Jan 2018.
How do I aggregate sales of models per part in a way that sales of part A still remains 100 in above example and not 200? Of course, I can create another table and perform aggregation separately. But would like to see if it can be done within the same table without creating several tables based on several other columns not shown in the example below.
Thanks for your help!
library(tidyverse)
library(lubridate)
vol <- data.frame(
Date = c("2018 Jan","2018 Jan","2018 Jan","2018 Jan",
"2018 Feb","2018 Feb","2018 Feb","2018 Feb",
"2019 Jan","2019 Jan","2019 Jan","2019 Jan",
"2019 Feb","2019 Feb","2019 Feb","2019 Feb"),
Country = c("CA","CA","US","US", "CA","CA","US","US", "CA","CA","US","US", "CA","CA","US","US"),
Part = c("A", "A", "B", "B", "A", "A", "B", "B", "A", "A", "B", "B", "A", "A", "B", "B"),
`Part Sales` = c(100, 100, 110, 110, 120, 120, 90, 90, 200, 200, 190, 190, 110, 110, 200, 200),
Model = c("M1", "M2", "M1", "M3", "M1", "M3", "M2", "M3", "M1", "M2", "M1", "M3", "M1", "M3", "M2", "M3"),
`Model Sales` = c(1000, 2000, 1000, 3000, 1120, 3120, 2090, 3120, 1200, 2200, 1200, 3120, 1110, 3110, 2200, 3110)
)
vol$Date <- ym(vol$Date)