I want to re-organize a longitudinal dataset in R. The original dataset looks like the one below.
| ID | y1_demo | y2_demo | y1_ex | y2_ex |
|---|---|---|---|---|
| 100 | A | B | A | B |
| 200 | B | A | A | C |
I would like to see the output like the following.
| ID | Year | demo | ex |
|---|---|---|---|
| 100 | Y1 | A | A |
| 100 | Y2 | B | B |
| 200 | Y1 | B | A |
| 200 | Y2 | A | C |