'R dataset restructuring

Hi, I have a dataset in R with this structure:

ID | Country | Year 1970 | Value |Product| Year 1971| Value| Product| Year 1972| Value |Product...

The columns repeated for each year, so I want to restructure the dataset in order to have the following structure:

Year | Product | Value | ID | Country |

Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source