I have a dataframe where I have the total number of points someone scored in the past 3 years (2016, 2017, 2018), but also columns with their number of points per year.
My dataframe looks like this:
myDF <- data.frame(ID =c(1,1,1,2,2,3,4),
Dates= c("2016", "2017", "2018", "2016", "2017", "2018", "2016"),
Total_Points = c(5, 5, 5, 4, 4, 2, 3),
Points2016 = c(3, NA, NA, 2, NA, NA, 3),
Points2017 = c(NA,1,NA,NA,2,NA,NA),
Points2018= c(NA,NA,1, NA, NA, 2, NA))
The problem is that I would like to copy the values of columns "Points2016", "Points2017" and "Points2017" for every group so that their entries look the same.
I'm not sure the explanation was clear so this would be my expected output:
myDF_final <- data.frame(ID =c(1,1,1,2,2,3,4),
Dates= c("2016", "2017", "2018", "2016", "2017", "2018", "2016"),
Total_Points = c(5, 5, 5, 4, 4, 2, 3),
Points2016 = c(3, 3, 3, 2, 2, NA, 3),
Points2017 = c(1,1,1,2,2,NA,NA),
Points2018= c(1,1,1, NA, NA, 2, NA))
Basically, I would like to have the same values for the columns "Points201X" for every ID.