Possibly a fairly simple question, however I have not been able to solve it so far. My goal is to redesign a data frame in R that has the following format:
var1 | year | Jan | Feb | March |
---|---|---|---|---|
x1 | 2019 | 1 | 2 | 3 |
x2 | 2020 | 2 | 2 | 3 |
x1 | 2020 | 1 | 2 | 2 |
x2 | 2019 | 3 | 1 | 1 |
to wide format: In the way that it results in the following table:
year | 2020 | 2020 | 2020 | 2019 | 2019 | 2019 |
---|---|---|---|---|---|---|
Jan | Feb | March | Jan | Feb | March | |
x1 | 1 | 2 | 2 | 1 | 2 | 3 |
x2 | 2 | 2 | 3 | 3 | 1 | 1 |
I am highly thankful for any advice or help!!