The code I have so far:
continuation <- data %>%
filter(TYPE == "group") %>%
select(ID, YEAR, COURSE_YEAR) %>%
group_by(ID) %>%
distinct(COURSE_YEAR) %>%
summarise(number = n())
Some sample data:
| ID | YEAR | COURSE_YEAR |
|---|---|---|
| 123545 | 2019 | 1 |
| 123545 | 2020 | 2 |
| 123654 | 2019 | 1 |
| 119236 | 2019 | 2 |
| 116787 | 2019 | 3 |
| 113435 | 2019 | 2 |
| 113435 | 2020 | 3 |
So I would want results something like
| Year | Course Years | No. |
|---|---|---|
| 2019 | 1 | 1 |
| 2019 | 1, 2 | 1 |
| 2019 | 2 | 1 |
| 2019 | 3 | 1 |
| 2019 | 2, 3 | 1 |
Course year has a range of values between 1 and 4. The distinct is needed as people may have multiple entries in the type column for each course year due to the nature of the underlying data.
I am trying to work out, for each of the years in the data set, how many ID numbers appear for the first time, and what combinations of course year there are. So I would expect most of the people appearing for the first time to have a course year of 1, but I'm interested in whether they are appearing in the data set for later years having progressed to the next year, or whether they are appearing for the first time with a course year != 1.