Your data:
structure(list(PatientID = c(1, 2, 3, 4), `Score Year1` = c(99,
52, 23, 22), `Score Year 2` = c(55, 22, 75, 84), `Score Year 3` = c(11,
1, 89, 51)), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -4L), spec = structure(list(cols = list(
PatientID = structure(list(), class = c("collector_double",
"collector")), `Score Year1` = structure(list(), class = c("collector_double",
"collector")), `Score Year 2` = structure(list(), class = c("collector_double",
"collector")), `Score Year 3` = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1), class = "col_spec"))
You need to convert it into the so called "long " format. For this you can use the pivot_longer() function from the tidyr package:
restructured = pivot_longer(data,
cols = -PatientID, # column PatientID should be kept
values_to = "Score", # the result should go into column "Score"
names_to = "Year", # years shoud go into column "Year"
names_prefix = "Score Year") %>% # the year columns contain now some text
mutate(Year = as.numeric(Year))
restructured
A tibble: 12 x 3
PatientID Year Score
1 1 1 99
2 1 2 55
3 1 3 11
4 2 1 52
5 2 2 22
6 2 3 1
7 3 1 23
8 3 2 75
9 3 3 89
10 4 1 22
11 4 2 84
12 4 3 51