Here is a solution using pivot_wider() from the tidyr package.
DF <- data.frame(Country = c("A", "A", "B", "B", "C", "C"),
Year = rep(c(2015, 2017), 3),
UHCindex = c(10, 9, 12, 14, 8, 18))
DF
Country Year UHCindex
1 A 2015 10
2 A 2017 9
3 B 2015 12
4 B 2017 14
5 C 2015 8
6 C 2017 18
library(tidyr)
pivot_wider(DF, names_from = Year, values_from = UHCindex,
names_prefix = "UHCindex")
# A tibble: 3 x 3
Country UHCindex2015 UHCindex2017
<chr> <dbl> <dbl>
1 A 10 9
2 B 12 14
3 C 8 18