Merging duplicated rows and create new column based on which rows were duplicated in R Let’s say I have the following: