I have a dataset similar to this:
Year | ID | Type
2000 1 O
2000 1 O
2000 1 O
2000 1 O
2000 1 R
2017 5 O
2017 5 O
2000 8 R
2000 8 O
2002 8 O
I want to create a code that groups the data by year and ID (I imagine it would use Dplyr) BUT it needs to have a condition: if in a given year there is any type R associated with an ID, then I want it to choose type R. If it has only O type, then the output must be O.
Example:
Year | ID | Type
2000 1 R
2017 5 O
2000 8 R
2002 8 O
Thank you all