I have the following dataset where ID has duplicates and other columns are categorical columns ranged from 0 t0 2. I'd like to select unique IDs with values of other columns that are not zero, if available. The data is as follows:
ID X Y R Z
1 0 2 0 1
1 0 2 0 0
2 1 0 0 1
3 1 1 0 1
3 1 1 1 1
4 0 0 1 0
4 0 1 1 0
My favourite outcome is:
ID X Y R Z
1 0 2 0 1
2 1 0 0 1
3 1 1 1 1
4 0 1 1 0
I am using dplyr and group_by
Thank you!