I have a data frame data that looks like the below:
data <- structure(list(ID = c("POTR_001341", "POTR_001341", "POTR_156376",
"POTR_001106", "POTR_001178", "POTR_001178", "POTR_234156", "POTR_234156",
"POTR_003709", "POTR_003709", "POTR_006406", "POTR_006406", "POTR_233767",
"POTR_233767"), label = c("non", "co", "co", "non", "non", "co",
"co", "non", "co", "non", "non", "co", "co", "non"), num = c(20,
2, 16, 8, 1, 1, 8, 2, 3, 3, 25, 3, 7, 7)), row.names = c(NA,
-14L), class = "data.frame")
I want to create a 4th column based on information present in the three columns.
If the ID is a duplicate like POTR_001341 check the label which has bigger num and give its label in the new_column and other as empty. It should look like below:
If the ID is not a duplicate, give the label in the new_column.
If the ID has a duplicate and both the labels non and co have the same digits in the column num, then give common in the new_column. It should look like
So, the final output should look like:




