We can also use melt from data.table which can also split by specifying any patterns in the column name. The regex ^ matches the beginning of the column name followed by substring 'ATM' or 'POS'. So, all the columns with 'ATM' will go into a single column 'ATM' while the 'POS' as next
library(data.table)
melt(setDT(df1), measure = patterns('^ATM', "^POS"),
value.name = c("ATM", "POS"), variable.name = "Year")
Or using pivot_longer with names_sep and specify the names_to so that it would split the columns at the delimiter _. The order of names_to indicates where the 'year' and the value in that column (.value) would go into. Here, we want the suffix of column name to be 'year' while the prefix (before the _) should get the values from that column
library(tidyr)
library(dplyr)
df1 %>%
pivot_longer(cols = -Country, names_to = c(".value", "Year"), names_sep="_")
# A tibble: 18 x 4
# Country Year ATM POS
# <chr> <chr> <dbl> <dbl>
# 1 A 2015 0.688 0.268
# 2 A 2014 0.920 0.453
# 3 A 2013 0.900 0.236
# 4 A 2012 0.964 0.972
# 5 A 2011 0.979 0.329
# 6 A 2010 0.756 0.578
# 7 B 2015 0.157 0.398
# 8 B 2014 0.651 0.0601
# 9 B 2013 0.944 0.711
#10 B 2012 0.942 0.684
#11 B 2011 0.0657 0.169
#12 B 2010 0.145 0.934
#13 C 2015 0.760 0.0501
#14 C 2014 0.895 0.301
#15 C 2013 0.602 0.263
#16 C 2012 0.732 0.508
#17 C 2011 0.902 0.953
#18 C 2010 0.583 0.0444
NOTE: Here it is based on the _. So, it can handle any number of columns and it is not true about what is described in another post
data
df1 <- structure(list(Country = c("A", "B", "C"), ATM_2015 = c(0.6883601,
0.1572208, 0.7599602), ATM_2014 = c(0.9199372, 0.6507811, 0.894864
), ATM_2013 = c(0.8996433, 0.9444197, 0.6020316), ATM_2012 = c(0.9644212,
0.9420349, 0.7315661), ATM_2011 = c(0.97940387, 0.06572698, 0.90211468
), ATM_2010 = c(0.7564401, 0.1445383, 0.5831917), POS_2015 = c(0.26770837,
0.39756729, 0.05011677), POS_2014 = c(0.45293675, 0.06007054,
0.30123347), POS_2013 = c(0.2363191, 0.7108505, 0.2633371), POS_2012 = c(0.9718356,
0.6843454, 0.5079645), POS_2011 = c(0.3290432, 0.169074, 0.9527117
), POS_2010 = c(0.57801166, 0.93432731, 0.04442355)), class = "data.frame",
row.names = c(NA,
-3L))