Friends, hello! I have a dataframe of some 2 million employees from one industry and the firms they have worked with from 2000-2019. It looks something like this:
| ID | FIRM | NAICS | Q1 | Q2 | Q3 | Q4 |
| A | 001 | 100 | 1 | 1 | 1 | 1 |
| B | 002 | 200 | 1 | 1 | 0 | 0 |
| B | 003 | 100 | 0 | 0 | 1 | 1 |
... where NAICS is the industry code of the company where someone worked in a given quarter. For example, Person A stayed in the same industry all four quarters; Person B moved from Industry 200 to Industry 100 in Q3 by moving firms.
The frame I would like to end up with looks like this:
| ID | Q1 | Q2 | Q3 | Q4 |
| A | 100 | 100 | 100 | 100 |
| B | 200 | 200 | 100 | 100 |
... so that I can track what industries people are coming from, and then build something akin to this NYT animated sankey diagram.
Could you help me figure out how to get from the first to the second? My hunch is that I need to be use dplyr::pivot_longer()
and dplyr::pivot_wider()
, which I understand are replacing spread()
and gather()
.