I have data in a dataframe that contains values across multiple years for different IDs. Currently, it appears as follows:
(can be recreated with the following code):
df<-data.frame(WLH_ID=c("15-7318","15-7318","15-7319","15-7319","15-7320","15-7320","15-7320"),
year=c("2017","2018","2017","2018","2017","2018","2019"),
overlap_95=c("1","1","0.626311190934023","0.968386735773874","0.713286882088087","0.824103998854928","0.451493099154607"))
I hope to reshape it to appear as follows::
Essentially I want to pull the value from the row so each year is in its own column- but keep the data in the same row as the ID if that makes sense so I can compare across each ID between years
Some IDs may have more years' worth of data than others, and in such cases, I would like the extra years to be represented as NAs or NULLs.
I am assuming this is something that can be done- just don't know where to start. I couldn't find this question already answered either but I could have worded it wrong.
Thanks in advance!