0

I have a dataset like this:

enter image description here

structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), year1 = c(2022, 
2020, 2023, 2022, 2020, 2023, 2022, 2020, 2023, 2022), year2 = c(2023, 
2022, 2024, 2023, 2022, 2024, 2023, 2022, 2024, 2023)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -10L))

For each ID, there are two years ("year1" and "year2"). I want to change the structure of the dataset so it looks like this:

enter image description here

Can somebody help me? Thank you

user19745561
  • 145
  • 10

0 Answers0