I would like to aggregate my costs by year
and by ID
.
Here is some example data:
ID <- c(1,1,1,1,2,2,3,3)
year <- c(1,2,2,2,3,3,3,3)
cost <- c(1,1,2,3,2,2,2,2)
data = cbind(ID, year, cost)
This information should be saved in additional column so costs_year1
, costs_year2
, costs_year3
by ID
. Then, I would drop the other columns and remove the duplicate IDs so I have a wide dataframe.
Any suggestions to do this neatly?