Основа R решение:
# Concatenate grouping vector:
dt$PC <- paste0(dt$Product, "_", dt$Country)
# Spread the vectors by year:
dt2 <- reshape(dt[,c(!(names(dt) %in% c("Product", "Country")))],
idvar = "Year",
ids = unique(dt$Year),
direction = "wide",
timevar = "PC")
# Remove "value.", from the vector names:
names(dt2) <- gsub("value[.]", "", names(dt2))
Данные:
dt <- expand.grid(Year = 1990:2014,
Product = LETTERS[1:8],
Country = paste0(LETTERS, "I"))
dt$value <- rnorm(nrow(dt))