I have a very long data table in the following format, where this here is just small a subset of the data table:
dt.data <- structure(list(delivDate = structure(c(20489, 20500, 20516, 20517,
20518, 20533, 20541, 20546, 20549, 20559, 20564, 20573, 20579,
20582, 20600), class = "Date"), priceDate = structure(c(19724,
19724, 19724, 19724, 19724, 19724, 19724, 19724, 19724, 19724,
19724, 19724, 19724, 19724, 19724), class = "Date"), priceIndex = c("HPFC DE",
"HPFC DE", "HPFC DE", "HPFC DE", "HPFC DE",
"HPFC DE", "HPFC DE", "HPFC DE", "HPFC DE",
"HPFC DE", "HPFC DE", "HPFC DE", "HPFC DE",
"HPFC DE", "HPFC DE"), avgPrice = c(109.65, 104.35,
104.5, 103.91, 100.38, 76.57, 66.72, 83.24, 47.7, 87.17, 86.65,
84.24, 83.68, 65.95, 83.73), quarters = c("Q1", "Q1", "Q1", "Q1",
"Q1", "Q1", "Q1", "Q2", "Q2", "Q2", "Q2", "Q2", "Q2", "Q2", "Q2"
)), row.names = c(NA, -15L), class = c("data.table", "data.frame"
))
Now, I want to create a new data table dt.meanPrice, where the avgPrice-column represents the mean of the prices per quarters, where the quarters are refered to the delivDate-column.
So, for each priceDate I want to get the average price per delivDate-quarters.