Detect in a line same values, and merge others

a reprex would make it easier to assist you as it would save a helper work in inventing examples of your data to demonstrate solutions on. FAQ: How to do a minimal reproducible example ( reprex ) for beginners

Are you familiar with the tidyverse package ? there are convenient functions therein.
filter() for dropping rows that meet conditions. mutate() to make new variable (perhaps to hold condition flags), case_when() is often useful for multivalue conditions, and base paste() function is oft used for merging character strings.