You should provide a reproducible example so that it is easier to provide you with an answer.

But anyway, I assume that it looks like this with the first column being a row number?

```
library(tidyverse)
df <- tibble::tribble(
~row, ~transplantid, ~drugcode, ~monthcode,
1L, 76L, "P", "Initial",
2L, 76L, "V", "Initial",
3L, 76L, "X", "Initial",
4L, 76L, "P", "3 Mth",
5L, 76L, "V", "3 Mth",
6L, 76L, "X", "3 Mth",
7L, 77L, "P", "Initial"
)
```

But then how do you get from here to the second bit? Where does VXU come from?